Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Scalable Restaurants

Building Scalable Restaurants

Victor Martinez

January 13, 2023
Tweet

More Decks by Victor Martinez

Other Decks in Programming

Transcript

  1. 3 WHO AM I? Where's the f*cking ring? Victor "Frodo"

    Martinez 31 y'old Pythonista - Coffee Lover - Backender A bit of everything at
  2. 14 • Bounded Contexts (DDD) • Different scalability necessities •

    Allow custom resource allocation ◦ Bathroom vs Dinner ◦ I/O Bound vs CPU Bound • … ARCHITECTURE DESIGN
  3. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 󰞽 🍳

    󰞽 󰳖 ⁉ How many cooks available?
  4. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 󰞽 🍳

    󰞽 How many clients per hour? 󰳖 ⁉
  5. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 󰞽 🍳

    󰞽 How many orders per hour? 󰳖 ⁉
  6. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 󰞽 🍳

    󰞽 👨 👩 👨 👩 👨 How many reservations per hour? 󰳖 ⁉
  7. KITCHEN HOST DINNER CASHIER WAITING ROOM BATHROOM BAR PERFORMANCE RESPONSE

    TIME → How much time takes a single request? Time to get an order ready
  8. KITCHEN HOST DINNER CASHIER WAITING ROOM BATHROOM BAR PERFORMANCE RESPONSE

    TIME → How much time takes a single request? Time to get an order ready SCALABILITY LOAD → Number of requests per period of time. Number of cooks available.
  9. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 👩 👨

    👩 👨 👩 👨 👩 👨 👩 👨 👩 👨
  10. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 👩 👨

    👩 👨 👩 👨 👩 👨 👩 👨 👩 👨
  11. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 👩 👨

    👩 👨 👩 👨 👩 👨 👩 👨 👩 👨
  12. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 👩 👨

    👩 👨 👩 👨 👩 👨 👩 👨 👩 👨 󰳖 ⁉
  13. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 👩 👨

    👩 👨 👩 👨 👩 👨 👩 👨 👩 👨 󰳖 ⁉ 1. How many orders per second? 2. How many contain errors? 3. How long do they take?
  14. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 👩 👨

    👩 👨 👩 👨 👩 👨 👩 👨 👩 👨 󰳖 ⁉ METRICS Traffic-based services (R.E.D.)
  15. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 👩 👨

    👩 👨 👩 👨 👩 👨 👩 👨 👩 👨 󰳖 ⁉ METRICS Traffic-based services (R.E.D.) RATE - ERROR - DURATION How many requests per second [RATE] Error percentage [ERROR] Duration/latency of each request [DURATION]
  16. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 👩 👨

    👩 👨 👩 👨 👩 👨 👩 👨 👩 👨 󰳖 ⁉ METRICS Traffic-based services (R.E.D.) RATE - ERROR - DURATION How many requests per second [RATE] Error percentage [ERROR] Duration/latency of each request [DURATION] OBS: Context is important (e.g. bad request)
  17. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 󰠉 HIGH

    AVAILABILITY 99.99% uptime Weak Redundancy Gateway Layer APP ❌ APP
  18. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 󰞽 ✋

    🔥 󰞽 󰞽 󰞽 󰞽 󰞽 󰞽 󰞽 󰞽
  19. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 󰞽 ✋

    🔥 󰞽 󰞽 󰞽 󰞽 󰞽 󰞽 󰞽 󰞽 FAULT TOLERANCE 100% uptime Strong Redundancy Gateway Layer APP ❌ APP APP APP
  20. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR ISOLATION OF

    STATE A service should not access another's database directly. A service should not access another's database directly. A B Well-defined API.
  21. ISOLATION OF SPACE A service should not care where others

    are placed. A B A A A A A B More services A does not imply into B.
  22. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR ♂ 🧾

    󰞽 ISOLATION OF TIME A service should not use sync & blocking requests. A B Message-driven & Eventual Consistency
  23. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 🕛 ✅

    ✅ ✅ ✅ ✅ ISOLATION OF FAILURE A service failure should not cause another to fail. A B Bulkheading - Circuit Breakers - Message Driven - Autonomy ✅
  24. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 󰞽 ✋

    🔥 ❌ ✅ ✅ ✅ ✅ ✅ ✅ BULKHEADING Failures are isolated into zones.
  25. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR ❌ ♂

    ✅ GATEWAY GATEWAY SERVICE A SERVICE B SERVICE C
  26. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR ♂ 🧾

    ♂ 🧾 ♀ ♀ 🧾🧾🧾 ❌ CIRCUIT-BREAKER A B CB
  27. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR ♂ 🧾

    ♂ 🧾 ♀ ♀ 🧾🧾🧾 ❌ CIRCUIT-BREAKER A B CB
  28. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR ♂ 🧾

    ♂ 🧾 ♀ ♀ 🧾🧾🧾 ❌ CIRCUIT-BREAKER A B CB CLOSED OPEN HALF- OPEN
  29. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 🧾 MESSAGE-DRIVEN

    Services should be able to send non-blocking async messages A B
  30. KITCHEN HOST DINNER CASHIER WAITING HALL BATHROOM BAR 🧾🧾 🧾

    🧾 🧾 🧾 ♂ 🧾 🧾 AUTONOMY & EVENTUAL CONSISTENCY After stopping receiving notifications all parts eventually converge to the same state. The only guarantee is that, at some point in the future, something good will happen. Data replication (when needed) Prevent long-running transactions [Saga] Compensation Actions vs Rollbacks
  31. 80 IN A NUTSHELL A scalable restaurant handles an increase

    in the number of clients as it responds to the necessities in a quick and efficient manner.
  32. 81 IN A NUTSHELL A scalable restaurant handles an increase

    in the number of clients as it responds to the necessities in a quick and efficient manner. How about software?
  33. 82 IN A NUTSHELL A scalable system handles an increase

    in the load as it responds to requests fast and efficiently.
  34. 84 HOW TO BUILD A SCALABLE RESTAURANT? More nodes. Isolation

    • Message-driven • Performance • Microservices • Bulkheading • Circuit Breakers • Gateways • Autonomy …
  35. 85 HOW TO BUILD A SCALABLE RESTAURANT? More nodes. Isolation

    • Message-driven • Performance • Microservices • Bulkheading • Circuit Breakers • Gateways • Autonomy … More nodes.
  36. 88 WHY? From 10 to 10 million users Use resources

    according to the load Failures cause a few or no effect in user experience Applications spread over hundreds/thousands of nodes RESPONSIVE experience under several conditions.
  37. 92 ELASTIC RESILIENT RESPONSIVE MESSAGE DRIVEN MAINTAINABLE EXTENSIBLE VALUE FORM

    MEANS ELASTIC 󰞽 Increase/decrease number of employees.
  38. 93 ELASTIC RESILIENT RESPONSIVE MESSAGE DRIVEN MAINTAINABLE EXTENSIBLE VALUE FORM

    MEANS RESILIENT 🔥 Replace employee in case of failure.
  39. 94 ELASTIC RESILIENT RESPONSIVE MESSAGE DRIVEN MAINTAINABLE EXTENSIBLE VALUE FORM

    MEANS MESSAGE DRIVEN 🧾 Take orders through async & non-blocking messages.
  40. 95 THERE STILL MUCH WORK TO BE DONE TRAFFIC-BASED MONITORING

    TRACES SHARDING CACHING CONTENTION RETRY IDEMPOTENCY …