Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
System Design Guide for Software Professionals

You're reading from   System Design Guide for Software Professionals Build scalable solutions – from fundamental concepts to cracking top tech company interviews

Arrow left icon
Product type Paperback
Published in Aug 2024
Publisher Packt
ISBN-13 9781805124993
Length 384 pages
Edition 1st Edition
Arrow right icon
Authors (2):
Arrow left icon
Dhirendra Sinha Dhirendra Sinha
Author Profile Icon Dhirendra Sinha
Dhirendra Sinha
Tejas Chopra Tejas Chopra
Author Profile Icon Tejas Chopra
Tejas Chopra
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Preface 1. Part 1: Foundations of System Design FREE CHAPTER
2. Chapter 1: Basics of System Design 3. Chapter 2: Distributed System Attributes 4. Chapter 3: Distributed Systems Theorems and Data Structures 5. Part 2: Core Components of Distributed Systems
6. Chapter 4: Distributed Systems Building Blocks: DNS, Load Balancers, and Application Gateways 7. Chapter 5: Design and Implementation of System Components –Databases and Storage 8. Chapter 6: Distributed Cache 9. Chapter 7: Pub/Sub and Distributed Queues 10. Part 3: System Design in Practice
11. Chapter 8: Design and Implementation of System Components: API, Security, and Metrics 12. Chapter 9: System Design – URL Shortener 13. Chapter 10: System Design – Proximity Service 14. Chapter 11: Designing a Service Like Twitter 15. Chapter 12: Designing a Service Like Instagram 16. Chapter 13: Designing a Service Like Google Docs 17. Chapter 14: Designing a Service Like Netflix 18. Chapter 15: Tips for Interviewees 19. Chapter 16: System Design Cheat Sheet 20. Index

A hotel room booking example

Before we jump into the different attributes of a distributed system, let’s set some context in terms of how reads and writes happen.

Let’s consider an example of a hotel room booking application (Figure 2.1). A high-level design diagram helps us understand how writes and reads happen:

Figure 2.1 – Hotel room booking request flow

Figure 2.1 – Hotel room booking request flow

As shown in Figure 2.1, a user (u1) is booking a room (r1) in a hotel and another user is trying to see the availability of the same room (r1) in that hotel. Let’s say we have three replicas of the reservations database (db1, db2, and db3). There can be two ways the writes get replicated to the other replicas: The app server itself writes to all replicas or the database has replication support and the writes get replicated without explicit writes by the app server.

Let’s look at the write and the read flows:

Write flow:

User (u1) books a room (r1). The device/client makes an API call to book a room (u1,r1) to the app server. The server writes to one, a few, or all of the replicas.

Read flow:

User (u2) checks the availability of room (r1). The device/client makes an API call in RoomAvailable (r1) to the app server. The server reads from one, a few, or all of the replicas.

Write options:

For write, we have the following options:

  • Serial sync writes: The server writes to db1 and gets an ack, then writes to db2 and gets an ack, and then writes to db3 and gets an ack. Finally, it acks the client. In this case, the response latency back to the user (u1) would be very high.
  • Serial async writes: The server writes to db1 and gets an ack. The server asks the client. Asynchronously, the server updates the other two replicas. Write latency is low.
  • Parallel async writes: The server fires three updates simultaneously, but doesn’t wait for all the acks, gets one (or k) acks, and then returns an ack to the client. Latency is low, but thread resource usage is high.
  • Write to a messaging service such as Kafka and return an ack to the client. A consumer then picks up the writes and follows any of the aforementioned options. Latency in this case is the lowest. It can support very high writes.

Read options:

For read, we have the following options:

  • Read from only one replica
  • Read from a quorum number of replicas
  • Read from all replicas and then return to the client

Each of these read options comes with consistency trade-offs. For example, if we read from only one replica, the read may be stale in some situations, posing a correctness problem. On the other hand, reading from all replicas and comparing all the values to determine which one is the latest value addresses the correctness problem, but this would be slower. Reading from a quorum number of replicas may be a more balanced approach. We will explore these trade-offs more in the following sections.

We will use this context in understanding the distributed system attributes.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image