advanced

Horizontal scaling

Add instances behind stateless boundaries while handling sessions, shared data, coordination, and deployment rollout.

Horizontal scaling adds more instances to handle load instead of bigger machines. It requires stateless application tiers, externalized sessions, shared caches or databases, and coordination for jobs that must not duplicate. Benefits include linear capacity growth and fault isolation; costs include network chatter, deployment complexity, and distributed debugging.

Use autoscaling on CPU, queue depth, or request latency with cooldowns to avoid flapping. Plan rolling deploys and health checks so new instances receive traffic safely.

On interviews: explain how you scale a stateless API tier, what you do with sticky sessions, and when horizontal scale stops helping.

Common pitfalls: local in-memory state breaking scale-out; thundering herd on cold instances; autoscaler lag during sudden spikes.

Checklist:

  • Keep app tier stateless or externalize state.
  • Define autoscaling signals and limits.
  • Plan session affinity only where required.
  • Measure coordination overhead at target scale.