I explained System Design to my friend using a pizza shop π
Turns out itβs the easiest way to get Scalability, Latency, Throughput, Consistency, and Availability!
1οΈ Scalability β More chefs, more pizzas
@RestController
class PizzaController {
@GetMapping("/order")
String orderPizza() { return "π Pizza ready!"; }
}
1 instance = 10 orders/min
10 instances = 100 orders/min
2οΈ Latency β How long until your pizza arrives?
@GetMapping("/order")
String orderPizza() throws InterruptedException {
Thread.sleep(3000); // 3 sec delay
return "π Pizza ready after wait!";
}
Delays = unhappy customers
3οΈ Throughput β Pizzas per minute
Run a load test:
ab -n 1000 -c 50 http://localhost:8080/order
One endpoint, but throughput depends on kitchen βpower.β
4οΈ Consistency β Pizza means pizza
@RestController
class PizzaController {
@GetMapping("/order")
String orderPizza() {
return Math.random() > 0.7 ? "π Pasta?" : "π Pizza";
}
}
Users want the same result every time!
5οΈ Availability β Always open
@GetMapping("/health")
String health() { return "β
Iβm alive!"; }
Service stays open, even if one instance crashes.
Takeaway
System design is like running a pizza shop π
- Scalability β more chefs
- Latency β wait time
- Throughput β orders per min
- Consistency β pizza = pizza
- Availability β always open
Whatβs your favorite system design analogy?
Top comments (0)