Preface

Part 1: Foundations of System Design

1

Basics of System Design

What is system design?

Software system

Distributed software system

Understanding system design

What are the types of system design?

High-level system design

System architecture

Data flow

Scalability

Fault tolerance

Low-level system design

Algorithms

Data structures

APIs

Code optimization

Importance of system design in the industry

Practical examples of the importance of system design

Summary

2

Distributed System Attributes

A hotel room booking example

Consistency

Strong consistency

Eventual consistency

Availability

Understanding partition tolerance

Network partition

Partition tolerance

Latency

Durability

Reliability

Fault tolerance

Scalability

Vertical scaling

Horizontal scaling

Summary

3

Distributed Systems Theorems and Data Structures

CAP theorem

PACELC theorem

Paxos

Raft

BGP

The Byzantine fault

Byzantine fault tolerance

Modern BFT

FLP impossibility theorem

Consistent hashing

Bloom filters

Count-min sketch

HyperLogLog

Summary

Part 2: Core Components of Distributed Systems

4

Distributed Systems Building Blocks: DNS, Load Balancers, and Application Gateways

Exploring DNS

DNS querying

Scalability, reliability, and consistency in DNS

Scalability

Reliability

Consistency

Load balancers

Placing load balancers

Advantages of load balancers

Global and local load balancing

DNS and GSLB

Load balancer algorithms

Load balancing at different layers of the Open Systems Interconnection (OSI) model

Deployment of load balancers

Implementing load balancers

Application gateways

Features and capabilities

Microservices architectures

Cloud-native implementations

On-premises options

Summary

5

Design and Implementation of System Components –Databases and Storage

Databases

Types of databases

Relational databases

NoSQL databases

The advantages and disadvantages of relational and NoSQL databases

NoSQL databases

Key-value stores

What is a key-value store?

Use in distributed systems

Designing a key-value store

Enhancing scalability and data replication

Boosting scalability

Consistent hashing

Virtual nodes

Data duplication strategies

Implementing get and put functions

Implementing get and put operations

Using r and w

Ensuring fault tolerance and identifying failures in a key-value store

Managing temporary failures

Addressing permanent failures

Ring membership promotion for failure detection

A system design interview – key value store design questions and strategies

DynamoDB

No fixed schema

API functions

Partitioning data in DynamoDB

Throughput optimizations in DynamoDB

High availability in DynamoDB

Column-family databases

HBase

HBase details

Graph-based databases

The Neo4j graph database

Neo4j details

Relational modeling versus graph modeling

Graph modeling

Adding a new node to an existing graph

Summary

References

6

Distributed Cache

What is caching?

What is distributed caching?

How is it different from regular caching?

Use cases

Benefits of using a distributed cache

Challenges of using distributed caching

Designing a distributed cache

Requirements

Design journey

Popular distributed cache solutions

Redis

Memcached

How to choose between Redis and Memcached

Summary

7

Pub/Sub and Distributed Queues

The evolution of distributed systems

Designing a distributed queue

Designing a pub/sub system

Key characteristics of pub/sub systems

Pub/sub system design considerations

Kafka

The importance of Kafka in distributed systems

Kafka Streams

Kinesis

Summary

Part 3: System Design in Practice

8

Design and Implementation of System Components: API, Security, and Metrics

REST APIs

Design principles of REST APIs

Use cases for REST APIs

Strengths and weaknesses

gRPC APIs

Design principles of gRPC APIs

Use cases for gRPC APIs

Strengths and weaknesses

Comparing REST and gRPC

API security

Authentication

Authorization

Secure communication of APIs

Rate limiting

Distributed systems logging

Centralized logging

Best practices for implementing distributed logging

Metrics in a distributed system

Types of metrics

Open source tools for metrics

Best practices for implementing metrics

Alerting in a distributed system

Designing effective alerts

Open-source tools for alerting

Best practices for implementing alerting

Tracing in a distributed system

Distributed tracing

Open-source tools for distributed tracing

Best practices for implementing tracing

Best practices

Summary

9

System Design – URL Shortener

Real-world use cases

Functional requirements

Non-functional requirements

Client APIs needed

Estimates and calculations

System design

Core challenge

Choice of database

High-level solution architecture

Requirements verification

Summary

10

System Design – Proximity Service

Real-world use cases

Functional requirements

Non-functional requirements

Client APIs needed

Estimates and calculations

System design

High-level system design

Core challenge

Final high-level solution architecture

Requirements verification

Summary

11

Designing a Service Like Twitter

Functional requirements

Non-functional requirements

Data model

Scale calculations

Exploring high-level design

Microservices architecture

Designing Tweet Service

Data storage

Tweet creation flow

Tweet retrieval flow

Caching

Designing User Service

Data storage

User registration flow

User authentication flow

Follow/unfollow flow

Retrieving followers/followees

Low-level design – Timeline Service

Data flow

Timeline retrieval flow

Push-based updates

Designing Search Service

Data flow and indexing

Search query processing

Relevance scoring and ranking

Additional considerations

Summary

12

Designing a Service Like Instagram

Functional requirements

Non-functional requirements

Designing the data model

Scale calculations

High-level design

Components and modules in the high-level architecture

Low-level design

Designing the Photo Upload Service

News Feed Service

User Service

Additional considerations

Summary

13

Designing a Service Like Google Docs

Functional requirements

Non-functional requirements

Data model

Relationships

Scale calculations

Assumptions

Storage requirements

Bandwidth considerations

Processing requirements

High-level design

Software components and modules of high-level design

Low-level design

Designing the document service

Designing the Collaboration Service

Designing the Access Control Service

Additional considerations and best practices

Summary

14

Designing a Service Like Netflix

Functional requirements

Non-functional requirements

Designing the data model

Relationships

Scale calculations

Assumptions

Storage estimation

Bandwidth estimation

Processing estimation

High-level design

Low-level system design

Video Service

Video upload and storage

Video encoding and transcoding

Video streaming

Caching and content delivery

User Service

User authentication and authorization

User profile management

Database and caching

Recommendation Service

The CDN

CDN architecture and content distribution

Request routing and video streaming

Adaptive bitrate streaming

Content security and DRM

Summary

15

Tips for Interviewees

Tips for preparation for system design interviews

Understanding the fundamentals

Studying common system design patterns

Practicing designing systems

Learning from online resources

Honing your communication skills

Reviewing and reflecting

Tips for the interview session

Understanding the problem statement

Breaking down the problem

Key steps to follow

Communicating your solution effectively

Summary

16

System Design Cheat Sheet

Which data store should we use for a use case?

Which data structures should we use for a use case?

Which components should we use for which use case?

What protocol should we use for which use case?

Which solution should we use for which core challenge?

Summary

Index