tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > ADK with Redis for High-Performance Session Storage

ADK with Redis for High-Performance Session Storage

Author: Venkata Sudhakar

The default InMemorySessionService in ADK stores sessions in local process memory. This means sessions are lost on pod restart, and two replicas cannot share session state. For production deployments with multiple replicas, Redis provides a shared, persistent session store with sub-millisecond read times - enabling truly stateful agent conversations at any scale.

ShopMax India runs its customer service agent with 12 replicas behind a load balancer. Without a shared session store, a customer whose conversation was handled by replica 3 would lose all context if their next message was routed to replica 7. With Redis-backed sessions, all 12 replicas share the same session state, and conversations are seamless even across process boundaries.

The below example shows a custom Redis session service that implements the ADK session interface, replacing InMemorySessionService.


It gives the following output,

Agent running with Redis-backed session storage
Redis connection: True

The below example shows how session persistence enables multi-replica conversation continuity - the same session continues seamlessly across different pods.


It gives the following output,

Session created: f8a2c91d...
Replica A: I can help you track order ORD-58291. Let me check the current status...
Session persisted in Redis: True
Replica B: Based on your order ORD-58291, the expected delivery is April 8th...

Replica B successfully continues the conversation about ORD-58291 without the customer needing to repeat their order number - the session context flowed seamlessly via Redis. For ShopMax India, this means customers get consistent, contextual service regardless of which of the 12 agent replicas handles each message. The 2-hour TTL means abandoned conversations expire automatically, preventing Redis memory from growing unboundedly during peak periods like Diwali sales.


 
  


  
bl  br