Restate Virtual Objects give your agents persistent, isolated sessions. Each session is identified by a unique key (like a user ID or conversation ID), maintains its own state, and has built-in concurrency control, so concurrent requests to the same session are automatically queued.
How it works
A Virtual Object is a Restate service type where each instance is identified by a key. State stored in a Virtual Object:
- Survives crashes and restarts: No external database needed
- Is isolated per key: Each session has its own state
- Has concurrency control: Only one write handler runs at a time per key, preventing race conditions
Example: a chat session
The state tab of the Restate UI lets you query the state of each session:
This pattern is complementary to AI memory solutions like mem0 or graffiti. You can use Virtual Objects to enforce session concurrency and queueing while storing the agent’s memory in specialized memory systems.
This pattern is implementable with any of our SDKs and any AI SDK.
If you need help with a specific SDK, please reach out to us via Discord or Slack.
Built-in concurrency control
Restate queues concurrent requests to the same session key. They are processed sequentially, preventing race conditions on shared state. This works similar to a task queue per session, but without needing to set up any external queue infrastructure.
Different session keys run in parallel with no interference.
Concurrently retrieving state
The state you store in Virtual Objects lives forever. To resume a session, simply send a new message to the same Virtual Object key.
This is a shared handler, meaning it can only read state (not write). This allows it to run concurrently with the message handler.