Skip to content

PATTERN Cited by 1 source

Sticky-session scatter-gather

When to use

You have a write-heavy API where requests carry a partition key, and you want each partition's processing to localize on one app instance — both to reduce cross-instance contention and to enable in-instance caching / batching of same- partition work.

The pattern

 clients ─► API gateway ──(route by partition-key)──► app instance N
              (scatter)                               (gather partition state
                                                      locally, process)
  • The gateway computes the partition key from the incoming request.
  • Routing is sticky per partition-key → the same partition always lands on the same instance.
  • Each instance maintains partition-local state (in-memory cache, actor mailbox, batch buffer).

Canonical example

Walmart's inventory-reservations API (summarized in the High Scalability Dec-2022 roundup) stacks three layers:

  1. Sticky-session scatter-gather (this pattern) — gateway routes by partition-key.
  2. Actor-per-partition with mailbox — in-instance concurrency control.
  3. In-memory snapshot-state cache — read-elimination.

See systems/walmart-inventory-reservations for the full stack.

Trade-offs

  • Partition-key hot-spots map to single-instance hot-spots — the pattern amplifies rather than smooths hot-key traffic.
  • Instance failure = partition failure until the gateway re-routes; the partition's in-memory state is lost on failover unless persisted.
  • Rebalance/scale-out is disruptive — repartitioning requires flushing in-memory state and coordinating the routing change.

Mitigations: combine with a persistent write-ahead log; route via consistent hashing so only a fraction of partitions rebalance on topology change.

Contrast with load-spreading

A naive "round-robin" load balancer explicitly avoids partition affinity — every instance can see any partition's requests. This is fine when the DB is the bottleneck and the instance layer is stateless; it breaks down when the instance layer is the natural place to keep per-partition state (caches, actor mailboxes, batch buffers).

Seen in

Last updated · 319 distilled / 1,201 read