An engineering case study on transforming a single-instance, in-memory connection manager into a horizontally scalable, deterministically sharded distributed system on Kubernetes.
A Real-Time Mailbox Connection Service maintained one persistent IMAP connection per email account to deliver live mailbox notifications and message access. The original design stored all connection state in memory, on a single process — which made the service impossible to scale horizontally without creating duplicate connections and corrupting request routing.
I owned the redesign end to end: converting a stateful single-instance service into a deterministically sharded, horizontally scalable distributed system running on Kubernetes.
Key technical achievements:
Impact: Reduced redundant connections by ~35%, and scaled the system from ~1.5K active connections on a single instance to 10K+ connections distributed across pods, with predictable, controllable rollouts.
This is the kind of problem where the hard part is not the code — it is making a fundamentally stateful workload behave correctly inside an orchestration layer that assumes statelessness.
The platform’s core value was real-time mailbox awareness — knowing immediately when a message arrived, moved, or changed in a connected mailbox. IMAP’s IDLE model makes this possible, but it requires a long-lived, persistent connection held open per account. That connection is inherently stateful: it lives in a process’s memory, tied to socket descriptors and session context.
The original service held all of these connections in-memory on one instance. As the number of connected accounts grew, this created a hard ceiling:
Why this was hard: Kubernetes is optimized for stateless, fungible workloads — any replica can serve any request. This service was the opposite: each unit of state (a connection) had to live in exactly one place, and traffic for that state had to find it. Reconciling a stateful workload with a stateless orchestration model is the central engineering tension of this project.