All jobs / Full-stack developer / System Design Basics
Full-stack developer interview question · 1–3 years
The API has run on a single server for a year, and you are adding a second behind a load balancer.
What in the current design is likely to break?
The strongest answer
Anything kept on the box: sessions and caches in process memory, files written to local disk, in-process timers and locks — they move to a shared store, to object storage, and to one scheduler
Why it works
Right — the question is always what this instance knows that the other one does not, and the answer has to be nothing that matters.
What a good answer covers
- Ask what the box knows.
- State moves to a shared store.
- Uploads go to object storage.
- One scheduler, not one per instance.
Answers that fall short
- Close, but not the strongest: The session, which we move to a shared cache or a signed cookie so either instance can serve the user
That is the first one, and local file uploads, an in-memory cache and a timer firing in both processes will bite you next. - Weak: Nothing, as long as the load balancer keeps each user on the same instance with sticky sessions
Stickiness hides the problem until an instance restarts and takes those users’ state with it, and it unbalances the load. - Red flag: Nothing — we deploy the same code to both, so the two instances behave identically
Identical code with local state is exactly the failure: the next request lands elsewhere and the state is not there.