I’m a longtime software engineer but new to python and backend. I’m wondering how developers are currently handling singletons (examples: database connection, rag index connection) in Langgraph, specifically Langgraph Platform.
I am trying to follow SOLID principles and have some sort of dependency injection, which I see is possible in python for example with FastAPI Depends().
If it’s not some dependency management system, how can I safely and in a production-friendly way, avoid global singletons? Are global singletons safe? Not sure what the implications if the langgraph platform instance is horizontally scaled.
Hi @sameer, did you come up with a good solution? I feel like I must be missing something because LangGraph just does not seem to have a good solution for this…
Hi @SpyMachine unfortunately no not really. I did see your thread on reddit and that LangChain Team @sydney-runkle posted Reddit - The heart of the internet
However my experience with Runtime Context has been very poor so far, I halted my migration from RunnableConfig until they iron out the kinks. And like you, I’m not clear on if we can have non serializable objects in there, and how in LangGraph Platform, how we can initialize things that would go into RuntimeContext from a FastAPI lifecycle event for example.
I don’t find the documentation sufficient or complete here
@sameer I’m trying to figure out this exact same thing at the moment. Please share if you have a solution. I looked through the langgraph_api code to see how I might be able to instrument the middleware but I didn’t see anything that could help.
Hi there, I think it might be possible from another thread that I had fired up.
Last time I played with RuntimeContext it was a mess so I’ve been staying away. I can’t personally vouch for this solution but you might find the information useful. Please do report back if you do