Module 07 · System Design · The stall, built · with code: Go · about 16 min to read
Continue where you left off ×
The stall, built: one counter in code (load balancing, health checks and caching in Go)
Design the Whole Thing · Open board
The whiteboard where every box had to be paid for by a number. This lesson takes three of those boxes, the gate, the slate and the rail, and writes them as one small program you can run on a laptop.
Before you start. You need the chai stall from The chai stall that got famous (load balancing) : one famous stall became three, and a man at the gate sends each customer to one of them, which is a load balancer. You need the slate from The slate next to the stove (caching) , a small board by the stove that remembers answers so the wala does not walk to the back room every time, which is a cache. You need the rail from The order slip rail (queues & the utilization cliff) , a wire of paper slips that lets the counter take an order now and cook it later, which is a queue. Design the Whole Thing (the interview, assembled) put all three on one whiteboard. This lesson turns that whiteboard into code. If you have never read Go, start with Reading Go in twenty minutes first.
The idea in 30 seconds
A load balancer that picks servers at random sends quick requests to busy servers. Picking the one with the fewest requests in progress removed that here (35 of 81 quick requests delayed, then none).
A load balancer can count each server’s line itself: add one when it sends a request, take one away when the answer returns.
A health check asks every server “are you up?” on a timer, and requests sent to a dead server in the gap between checks fail.
A cache answers a repeat question in nanoseconds, where the store behind it takes milliseconds, so the store only sees the misses.
A queue hands back a token at once and does the work later, and a bounded queue that refuses when full is backpressure.
Read the story
Lesson 41 of 115 in System Design
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson February 2013: a lyrics site finds its gate was guessing The stall as a program The load balancer that guesses, and the one that counts A stall shuts mid-rush: the health check The cache by the stove: a hit in nanoseconds, a miss in 20 ms The queue that says “kitchen full” What the stall still cannot do Terms it explains: load balancer, health check, cache, queue, backpressure, least connections.
Review System Design
Mark as read Saved in this browser, and to your account when you sign in.