Skip to content

Add Redis-backed session storage to support multi-pod ChatBI deployments#364

Draft
meta-d with Copilot wants to merge 5 commits into
developfrom
copilot/fix-k8s-request-failures
Draft

Add Redis-backed session storage to support multi-pod ChatBI deployments#364
meta-d with Copilot wants to merge 5 commits into
developfrom
copilot/fix-k8s-request-failures

Conversation

Copilot AI commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Multiple ChatBI pods failed randomly due to in-memory session loss when requests hit different replicas.

  • Session storage: Replace in-memory Express sessions in both analytics and server bootstraps with Redis-backed stores (connect-redis + redis), with validation of EXPRESS_SESSION_SECRET, Redis error logging, and automatic fallback to in-memory if Redis is unavailable.
  • Dependencies: Add connect-redis to analytics/server packages and update yarn.lock.
  • Consistency: Standardize session warning/log messages across bootstraps.

Example (analytics/server bootstrap):

const redisClient = createClient({ url: redisUrl, socket: process.env.REDIS_TLS === 'true' ? { tls: true } : undefined });
redisClient.on('error', (error) => Logger.error(`Redis session client error: ${error?.message ?? error}`));
await redisClient.connect();

const sessionOptions: SessionOptions = {
  secret: env.EXPRESS_SESSION_SECRET,
  resave: false,
  saveUninitialized: false,
  store: new RedisStore({ client: redisClient, prefix: 'sess:' }),
  cookie: { secure: env.production } // analytics only
};
app.use(expressSession(sessionOptions));

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.cypress.io
    • Triggering command: /usr/local/bin/node /usr/local/bin/node index.js --exec install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>K8s Deployment: Multiple instances cause request failures due to missing shared memory</issue_title>
<issue_description>## Problem Description

When deploying ChatBI to a Kubernetes cluster, requests randomly get routed to different ChatBI instances due to load balancing. Since there is no shared memory/session state between instances, this causes request failures.

Current Behavior:

  • Single instance deployment: Works correctly ✓
  • Multiple instances in K8s cluster: Random request failures ✗

Root Cause:

  • Different replicas/instances have isolated in-memory state
  • Requests from the same session may be routed to different pods
  • No distributed session management or shared cache layer

Expected Behavior

ChatBI should work correctly with multiple instances in a Kubernetes cluster, with requests properly handling session/state across instances.

Solutions to Consider

  1. Implement distributed session management

    • Use Redis or similar for session storage
    • Replace in-memory sessions with shared cache
  2. Implement sticky sessions

    • Configure load balancer to route requests from same client to same pod
    • Less ideal but simpler workaround
  3. Add session affinity in K8s

    • Use sessionAffinity in Kubernetes Service configuration
  4. Implement state sharing mechanism

    • Create a shared data layer for instance-specific state
    • Could use Redis, Memcached, or similar

Affected Components

  • ChatBI deployment architecture
  • Session management
  • K8s service configuration

Environment

  • Deployment: Kubernetes cluster
  • Instance count: Multiple replicas
  • Works: Single instance (non-K8s) ✓</issue_description>

<agent_instructions>Please investigate this issue and provide a proposed solution. We will discuss it and then make the necessary modifications.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 12, 2026 08:37
Co-authored-by: meta-d <100019674+meta-d@users.noreply.github.com>
Co-authored-by: meta-d <100019674+meta-d@users.noreply.github.com>
Co-authored-by: meta-d <100019674+meta-d@users.noreply.github.com>
Co-authored-by: meta-d <100019674+meta-d@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix request failures due to missing shared memory in K8s deployment Add Redis-backed session storage to support multi-pod ChatBI deployments Jan 12, 2026
Copilot AI requested a review from meta-d January 12, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants