System Design

Chapter 1 — System Design Foundations for Staff & Principal Engineers

Staff and principal level system design interview guidance, trade-offs, and architecture framework.

Deepak Mishra39 min read


Chapter 1 — System Design Foundations for Staff & Principal Engineers

Interview principle: System design is not a component-drawing exercise. It is the disciplined process of turning ambiguous product goals into a reliable, scalable, secure, observable, and economically viable system — while making explicit trade-offs.


1. What System Design Interviews Actually Evaluate

At Senior level, an interviewer wants to know whether you can design a working system.

At Staff/Principal level, the bar is higher:

  • Can you turn ambiguous requirements into explicit engineering decisions?
  • Can you reason quantitatively about scale and capacity?
  • Can you identify the real bottleneck rather than listing technologies?
  • Can you distinguish hard requirements from negotiable ones?
  • Can you reason about failure, recovery, consistency, and operational burden?
  • Can you explain why an apparently simpler design is insufficient?
  • Can you evolve the architecture as traffic, data, teams, and business requirements change?
  • Can you optimize not only for performance, but also for cost, reliability, developer velocity, and organizational complexity?

A strong Staff/Principal candidate continuously connects:

Business Goal

User Experience

Requirements

Scale & Constraints

APIs + Data Contracts

Architecture

Bottlenecks & Failure Modes

Reliability + Security + Observability

Cost + Operational Model

Evolution Strategy

The uploaded system-design archive emphasizes that effective system design is fundamentally a trade-off exercise, spanning application architecture, networking, data, scalability/reliability, security/observability, and infrastructure/deployment concerns.


2. The Staff/Principal System Design Framework

Use the following framework for almost every interview.

1. Requirements

2. Scale Estimation

3. API / Data Contracts

4. High-Level Architecture

5. Data Model & Storage

6. Deep Dive

7. Bottlenecks & Failure Modes

8. Reliability / Scalability

9. Security / Observability

10. Cost / Capacity

11. Trade-offs

12. Evolution

Do not treat this as a rigid script. The interviewer may take you directly into a deep dive. Your responsibility is to maintain a coherent mental model.

Staff-level behavior

A Staff engineer says:

“We have 10 million daily active users, but the key number for this endpoint is peak write QPS. Let me estimate that first because it determines whether a single relational primary is sufficient.”

Principal-level behavior

A Principal engineer goes one step further:

“I can make this scale horizontally, but before doing that I want to establish whether the product actually needs that scale. If the business can tolerate five minutes of delayed processing, an asynchronous architecture may reduce both infrastructure cost and operational complexity.”

That distinction — engineering for the actual constraint rather than the imagined constraint — is one of the strongest senior-level signals.


3. Requirements Clarification

Never start by drawing microservices.

Start by understanding what must be built.

3.1 Functional Requirements

Functional requirements describe what the system does.

For a URL shortener:

  • Create a short URL.
  • Redirect a short URL to the original URL.
  • Optionally track click analytics.
  • Support expiration.
  • Support authenticated users.

For a notification system:

  • Accept notification requests.
  • Select a delivery channel.
  • Deliver notifications.
  • Retry temporary failures.
  • Track delivery status.

Interview technique

State the scope explicitly:

“For the first version, I will focus on URL creation and redirection. I will treat analytics and custom aliases as secondary requirements unless you want me to include them.”

This demonstrates prioritization.


3.2 Non-Functional Requirements

Non-functional requirements describe how well the system must behave.

Typical NFRs include:

NFR Example target Architectural impact
Availability 99.99% Redundancy, failover, health checks
P99 latency < 200 ms Caching, indexing, locality
Durability 11 nines for object data Replication, durable storage
Throughput 100K writes/sec Partitioning, batching
Scalability 10× growth Horizontal scaling
Consistency Strong for payments Transactions / consensus
Recovery RTO < 30 min Multi-region DR
Data loss RPO < 5 min Replication / log shipping
Security Tenant isolation AuthN/AuthZ, encryption
Cost <$X/month Capacity planning and tiering

The archive highlights availability, latency, scalability, durability, consistency, modularity, configurability, and resiliency as important quality attributes.

Staff/Principal insight

Do not say:

“The system should be highly available.”

Say:

“Let’s target 99.99% monthly availability for the API. That gives us an approximate error budget of 4.38 minutes per 30-day month.”

The number changes the architecture.


3.3 Clarifying Questions

Ask questions that materially change the design.

Users and traffic

  • How many users?
  • Daily active users?
  • Peak concurrent users?
  • Geographic distribution?
  • Read/write ratio?
  • Traffic seasonality?

Data

  • How much data is created per day?
  • Retention period?
  • Data growth rate?
  • Does data need to be deleted?
  • Is the workload transactional or analytical?

Consistency

  • Must reads immediately reflect writes?
  • Is eventual consistency acceptable?
  • What happens if a user sees stale data?

Availability

  • Is downtime acceptable?
  • What is the target SLA?
  • Is multi-region required?

Latency

  • Is this interactive?
  • Is 100 ms important, or is 5 seconds acceptable?
  • Are asynchronous responses acceptable?

Security

  • Public or private?
  • Authentication?
  • Multi-tenancy?
  • Regulatory requirements?
  • Encryption requirements?

Business constraints

  • Budget?
  • Time to market?
  • Expected growth?
  • Existing infrastructure?

Interview Questions

  • Which requirement would you clarify first?
  • Which NFR changes your architecture the most?
  • What happens if the interviewer changes availability from 99.9% to 99.99%?
  • Which requirements are hard constraints and which are optimization targets?
  • What would you deliberately leave out of V1?

4. Scale Estimation and Capacity Planning

Scale estimation is one of the clearest ways to demonstrate senior-level thinking.

You do not need perfect numbers.

You need transparent assumptions and order-of-magnitude reasoning.

4.1 QPS Estimation

Suppose:

  • 100 million daily active users
  • Each user performs 20 API operations/day

Total operations:

$$ 2 \times 10^9 \text{ operations/day} $$

Average QPS:

$$ QPS_{avg} = \frac{2 \times 10^9}{86,400} \approx 23,148 $$

Assume a peak factor of 5:

$$ QPS_{peak} = 23,148 \times 5 \approx 116,000 $$

Therefore, design around roughly 120K peak QPS, not 23K.


4.2 Read/Write Split

Suppose the workload is:

  • 90% reads
  • 10% writes

At 120K peak QPS:

$$ QPS_{read}=120,000 \times 0.9=108,000 $$

$$ QPS_{write}=120,000 \times 0.1=12,000 $$

This immediately suggests that read optimization may provide more value than write optimization.

Potential strategies:

  • CDN
  • application cache
  • database read replicas
  • denormalized read models
  • search indexes
  • precomputed aggregates

4.3 Storage Estimation

Suppose:

  • 12 million writes/day
  • Average record size = 2 KB
  • Retention = 3 years

Daily raw storage:

$$ 12,000,000 \times 2\text{ KB} =24\text{ GB/day} $$

Three-year raw storage:

$$ 24 \times 365 \times 3 \approx 26.3\text{ TB} $$

With three replicas:

$$ 26.3 \times 3 \approx 78.9\text{ TB} $$

Add indexes, metadata, logs, backups, and headroom. A realistic capacity plan may therefore require substantially more than 79 TB.

Staff/Principal insight

Do not stop at:

“We need 80 TB.”

Continue:

“I would provision additional headroom because storage growth, compaction, indexes, replicas, and operational reserves can materially increase the physical footprint.”


4.4 Bandwidth

If an endpoint returns 10 KB per response and peak QPS is 100K:

$$ Bandwidth = 100,000 \times 10\text{ KB} =1,000,000\text{ KB/s} $$

Approximately:

$$ 1\text{ GB/s} $$

That is about:

$$ 8\text{ Gbit/s} $$

before protocol overhead.

This can change the architecture dramatically.

For large payloads, consider:

  • CDN
  • compression
  • pagination
  • streaming
  • object storage
  • signed URLs
  • edge caching

4.5 Memory and Cache Sizing

Suppose a cache stores:

  • 10 million objects
  • Average object = 2 KB
  • 50% memory overhead

Approximate memory:

$$ 10,000,000 \times 2\text{ KB} \times 1.5 \approx 30\text{ GB} $$

Then add:

  • replication
  • eviction headroom
  • metadata
  • fragmentation
  • failover capacity

A Staff engineer should avoid designing a cache at 100% memory utilization.


Interview Questions

  • What is your peak QPS?
  • What is the read/write ratio?
  • How much storage do you need after three years?
  • What happens if traffic grows 10×?
  • What is your bandwidth requirement?
  • How much cache memory is required?
  • What assumptions have the highest uncertainty?

5. Latency vs. Throughput

The archive correctly emphasizes that latency and throughput represent different dimensions of performance.

Latency is the time required for an operation.

Throughput is the amount of work completed per unit time.

A system can have:

  • low latency but low throughput
  • high throughput but high latency
  • both high
  • neither

For example, batch processing may tolerate seconds or minutes of latency while requiring very high throughput.

5.1 Latency Budget

Suppose an API has a P99 target of 200 ms.

A possible budget:

Component Budget
Network 30 ms
API gateway 10 ms
Application 40 ms
Cache 10 ms
Database 60 ms
External dependency 30 ms
Safety margin 20 ms
Total 200 ms

If an external API alone consumes 250 ms at P99, no amount of application-level optimization will meet a 200 ms end-to-end target.

That is the value of a latency budget.


5.2 Queueing Matters

As utilization approaches saturation, queueing delay can rise sharply.

Therefore:

Do not design systems to run permanently at 100% utilization.

Leave capacity for:

  • traffic bursts
  • retries
  • failover
  • maintenance
  • noisy neighbors
  • cache misses

Interview Questions

  • Where is the latency budget spent?
  • Which component dominates P99?
  • What happens when utilization reaches 90%?
  • Is this latency-sensitive or throughput-sensitive?
  • Would asynchronous processing improve the user experience?

6. High-Level Architecture

Once requirements and scale are clear, draw the simplest architecture that satisfies them.

A common production web architecture is:

flowchart LR
    Client --> DNS
    DNS --> CDN
    CDN --> LB
    LB --> Gateway
    Gateway --> Service
    Service --> Cache
    Service --> DB
    Service --> Queue
    Queue --> Worker
    Worker --> DB
    Service --> Search
    Service --> Observability

The archive’s production-web-application architecture includes CI/CD, DNS, load balancing/reverse proxies, CDN, APIs, databases/caches, job queues, search, monitoring, and alerting.

The important Staff-level question is not:

“Can I add more components?”

It is:

“Which component exists because a specific requirement demands it?”


7. Load Balancing

Load balancing distributes traffic across multiple service instances.

It helps with:

  • availability
  • horizontal scaling
  • fault isolation
  • connection distribution
  • maintenance without complete downtime

Common strategies include:

  • round robin
  • weighted routing
  • least connections
  • latency-aware routing
  • consistent hashing

Load Balancer vs API Gateway

Dimension Load Balancer API Gateway
Primary role Traffic distribution API policy and routing
Layer Usually L4/L7 Usually L7
Routing Host/path/service Rich API-aware routing
Authentication Limited/possible Common
Rate limiting Sometimes Common
Transformation Limited Common
Business policy Usually no Often yes
Service aggregation Rare Possible

They can coexist.

Client

CDN

Load Balancer

API Gateway

Services

Do not assume every architecture needs both.

Staff/Principal insight

Ask:

“Is the gateway solving a real policy problem, or are we introducing another distributed component that increases latency and operational complexity?”


8. API and Data-Contract Design

APIs are contracts between independently evolving components.

The archive covers REST, SOAP, GraphQL, gRPC, WebSockets, authentication, pagination, idempotency, versioning, performance, gateways, and integration patterns.

8.1 REST Example

POST /v1/orders
GET /v1/orders/{order_id}
GET /v1/orders?customer_id=123&limit=50&cursor=abc
POST /v1/orders/{order_id}/cancel

A strong API should define:

  • resource semantics
  • request schema
  • response schema
  • error model
  • authentication
  • authorization
  • idempotency
  • pagination
  • versioning
  • rate limits
  • timeout expectations

8.2 Idempotency

Idempotency is particularly important for financial or state-changing operations.

Suppose a client submits:

POST /payments
Idempotency-Key: 9f2a...

If the client retries because of a timeout, the server should not create two payments.

Conceptually:

Request

Idempotency Store

Already processed? ── Yes ──> Return previous result

   No

Process operation

Persist result

Staff-level point

Retries without idempotency can turn a transient network failure into a business-level duplicate.


9. REST vs gRPC vs GraphQL vs WebSockets

Technology Strength Best fit Main trade-off
REST Simple, ubiquitous Public APIs Can require multiple round trips
gRPC Efficient typed RPC Internal service-to-service Less browser-friendly
GraphQL Flexible client queries Complex read APIs Query complexity and governance
WebSockets Bidirectional real-time Chat, collaboration Connection management
Async messaging Decoupling Background/event workflows Eventual consistency

The source describes gRPC as using Protocol Buffers and HTTP/2. A more accurate interview statement is:

gRPC can provide efficient binary serialization, multiplexing, streaming, and strongly typed contracts, but there is no universal “5× faster” guarantee. Performance depends on payloads, serialization, network behavior, implementation, and workload.

That is the kind of correction a Principal engineer should make when presenting architecture.


Interview Questions

  • Why REST instead of gRPC?
  • Why synchronous communication?
  • Where would you use asynchronous messaging?
  • How do you version an API?
  • How do you prevent duplicate requests?
  • What happens when a downstream service is unavailable?

10. Stateless Services

A stateless service does not require a specific application instance to remember request state.

flowchart LR
    Client --> LB
    LB --> S1
    LB --> S2
    LB --> S3
    S1 --> SharedState
    S2 --> SharedState
    S3 --> SharedState

Benefits:

  • easy horizontal scaling
  • easier failover
  • simpler deployments
  • better elasticity

State may live in:

  • database
  • distributed cache
  • object storage
  • durable event log

Important nuance

Stateless does not mean the overall system has no state.

It means request-serving instances do not rely on local state for correctness.


11. Caching

Caching is one of the most powerful performance techniques.

A typical flow:

flowchart LR
    Client --> Service
    Service --> Cache
    Cache -->|Hit| Service
    Cache -->|Miss| DB
    DB --> Cache
    Cache --> Service

Cache-aside

  1. Application checks cache.
  2. On hit, return data.
  3. On miss, read database.
  4. Populate cache.
  5. Return response.

Cache trade-offs

Decision Option A Option B Trade-off
Location Local cache Distributed cache Latency vs shared consistency
Population Lazy Proactive Simplicity vs predictable latency
Expiration TTL Explicit invalidation Freshness vs complexity
Eviction LRU LFU Recency vs frequency
Failure Fail-open Fail-closed Availability vs protection

11.1 Cache Failure Modes

The archive identifies several important cache problems.

Cache penetration

Requests repeatedly target nonexistent keys.

Mitigations:

  • negative caching
  • Bloom filters
  • request validation

Cache breakdown / stampede

A hot key expires and many requests simultaneously hit the database.

Mitigations:

  • request coalescing
  • jittered TTLs
  • background refresh
  • locking/single-flight
  • stale-while-revalidate

Cache outage

The cache becomes unavailable and traffic floods the database.

Mitigations:

  • cache clustering
  • circuit breakers
  • local fallback
  • database protection
  • admission control

Staff/Principal insight

Caching is not free performance.

It introduces:

  • consistency problems
  • invalidation complexity
  • memory cost
  • failure modes
  • operational dependencies

The correct question is:

“What failure behavior do we want when the cache is wrong or unavailable?”


12. Database and Storage Selection

Do not choose a database because it is popular.

Choose based on workload.

12.1 SQL

Good fit when you need:

  • transactions
  • relational integrity
  • joins
  • mature query capabilities
  • strong consistency

Examples:

  • payments
  • orders
  • inventory
  • account systems

12.2 Key-Value

Good fit for:

  • sessions
  • counters
  • configuration
  • high-volume point lookups

12.3 Document

Good fit for:

  • flexible schemas
  • aggregates that are naturally retrieved together
  • rapidly evolving document-shaped data

12.4 Search Engine

Good fit for:

  • full-text search
  • relevance ranking
  • filtering
  • faceting

Do not use a search engine as the system of record unless its guarantees genuinely match the requirement.

12.5 Object Storage

Good fit for:

  • images
  • videos
  • documents
  • backups
  • data lakes

Storage Decision Table

Requirement Likely choice
ACID transactions Relational DB
Massive key lookup Key-value store
Flexible aggregates Document DB
Full-text search Search engine
Large immutable blobs Object storage
Time-series metrics Time-series database
Analytics at scale Data warehouse/lake
Embeddings Vector-capable store

13. Replication vs Sharding

These concepts solve different problems.

Replication

Copies data across nodes.

Primary goals:

  • availability
  • fault tolerance
  • read scaling
             ┌── Replica 1
Primary ─────┼── Replica 2
             └── Replica 3

Sharding

Partitions data across nodes.

Primary goals:

  • storage scaling
  • write scaling
  • workload distribution
Users A-F  → Shard 1
Users G-M  → Shard 2
Users N-S  → Shard 3
Users T-Z  → Shard 4

They are often combined:

Shard 1 → Primary + Replicas
Shard 2 → Primary + Replicas
Shard 3 → Primary + Replicas

Principal-level concern: shard key

A poor shard key creates:

  • hot partitions
  • uneven storage
  • uneven traffic
  • expensive rebalancing

Ask:

“What access pattern determines the partition key?”


14. Consistency, Availability, and Partitions

Distributed systems force trade-offs.

The archive summarizes CAP as a trade-off among consistency, availability, and partition tolerance.

The interview-level nuance is:

In a distributed system, network partitions can occur. During a partition, the system must make a trade-off between serving potentially stale/inconsistent results and refusing some operations.

Examples:

Payment authorization

Prefer stronger consistency.

Social-media like count

Eventual consistency may be acceptable.

Search index

Usually eventually consistent with the primary data.

User profile

A small amount of staleness may be acceptable depending on the product.


Consistency Decision Table

Use case Typical preference
Payment balance Strong
Inventory reservation Strong / carefully coordinated
Social likes Eventual
Search index Eventual
Analytics dashboard Eventual
Configuration Depends on blast radius
Session revocation Stronger semantics often required

Staff/Principal question

Do not ask only:

“Strong or eventual?”

Ask:

“What is the business consequence of stale data?”

That determines the appropriate consistency model.


15. Asynchronous Processing and Messaging

Long-running work should not unnecessarily block interactive requests.

flowchart LR
    Client --> API
    API --> DB
    API --> Queue
    Queue --> Worker1
    Queue --> Worker2
    Queue --> Worker3
    Worker1 --> ExternalSystem
    Worker2 --> ExternalSystem

Good candidates:

  • email
  • notification delivery
  • video processing
  • report generation
  • analytics
  • search indexing
  • embedding generation
  • batch inference

Benefits:

  • decoupling
  • buffering
  • retry
  • workload smoothing
  • independent scaling

Costs:

  • eventual consistency
  • duplicate processing
  • ordering complexity
  • observability complexity
  • dead-letter handling

At-Least-Once Delivery

Many messaging systems provide at-least-once semantics.

Therefore:

Consumers should be designed to tolerate duplicate messages.

Typical techniques:

  • idempotency keys
  • deduplication tables
  • deterministic operations
  • transactional outbox
  • consumer offsets/checkpoints

16. Reliability and Fault Tolerance

Reliability is not “adding replicas everywhere.”

Start with failure scenarios.

Failure Matrix

Failure Detection Mitigation Recovery
Service instance crash Health check Load balancing Restart
Cache outage Metrics Fallback/circuit breaker Cluster recovery
DB primary failure Replication health Automatic failover Replica promotion
Queue backlog Queue depth Scale workers Drain backlog
Region outage Synthetic monitoring Multi-region Traffic failover
Dependency timeout Tracing Timeout/circuit breaker Retry/fallback
Bad deployment Error-rate alert Canary/rollback Revert

16.1 Timeouts

Every network call should have an intentional timeout.

Without timeouts:

Request

Service A
  ↓ waits
Service B
  ↓ waits
Service C

Thread pool exhausted

Service A unavailable

Timeouts prevent indefinite resource occupation.


16.2 Retries

Retries can help transient failures.

But careless retries create retry storms.

Example:

1000 requests

Dependency fails

1000 retries

Dependency receives 1000 more requests

More overload

More failures

Use:

  • exponential backoff
  • jitter
  • retry budgets
  • maximum attempts
  • idempotency

16.3 Circuit Breakers

A circuit breaker stops repeatedly calling an unhealthy dependency.

States:

CLOSED
  ↓ failures exceed threshold
OPEN
  ↓ wait
HALF-OPEN
  ↓ successful probe
CLOSED

The archive identifies circuit breaking as a useful API-gateway resilience mechanism.


17. Availability and Error Budgets

Availability is often expressed as:

$$ Availability = \frac{Successful\ Time}{Total\ Time} $$

Approximate monthly downtime for a 30-day month:

Availability Approx. downtime/month
99% 7.2 hours
99.9% 43.2 minutes
99.99% 4.32 minutes
99.999% 25.9 seconds

A higher SLA is not merely a monitoring number.

It can require:

  • redundancy
  • automated failover
  • multi-zone architecture
  • multi-region deployment
  • stronger operational practices
  • more testing
  • higher cost

18. Disaster Recovery

Define two concepts:

RTO — Recovery Time Objective

How quickly must the service recover?

RPO — Recovery Point Objective

How much data loss is acceptable?

Example:

RTO = 30 minutes
RPO = 5 minutes

This means:

  • service should recover within 30 minutes
  • data loss should be no more than approximately 5 minutes

DR Strategies

Strategy Recovery Cost
Backup/restore Slow Low
Pilot light Medium Medium
Warm standby Fast Higher
Active-active Very fast Highest

Principal-level insight

Do not propose active-active multi-region automatically.

Ask:

  • Is the SLA worth the cost?
  • Can the database support it?
  • How is conflict resolution handled?
  • How is global consistency achieved?
  • What happens during a partial regional failure?
  • How will failback work?

19. Security by Design

Security is an architectural concern, not a final checklist.

The source archive highlights HTTPS, OAuth2, WebAuthn, API keys, authorization, rate limiting, versioning, allow-listing, OWASP API risks, API gateways, error handling, and input validation.

Security Layers

Client

TLS

Gateway
  ├── Authentication
  ├── Authorization
  ├── Rate Limiting
  ├── Input Validation
  └── Threat Detection

Application

Data Layer
  ├── Encryption at rest
  ├── Access control
  └── Audit logging

Authentication vs Authorization

Authentication: Who are you?

Authorization: What are you allowed to do?

Example:

User authenticates

Identity = user-123

Role = ADMIN

Can user perform DELETE /users/456?

Authorization decision

20. Sessions, Cookies, JWT, and OAuth

These concepts are frequently confused.

The browser stores a session identifier in a cookie.

Server-side state stores the session.

Advantages:

  • easy revocation
  • server-controlled state
  • small client-side credential

Trade-off:

  • requires shared session state or routing strategy in a distributed deployment

JWT

JWT is a signed token format.

It can carry claims and can be validated without looking up session state on every request.

Important correction:

JWT is not automatically encrypted, and it does not mean “all user data is stored in the token.” Sensitive data should not be placed in a token merely because it is base64url encoded.

Trade-offs:

  • easy distributed validation
  • token size
  • revocation complexity
  • key rotation
  • token theft risk

OAuth 2.0

OAuth 2.0 is primarily an authorization framework for delegated access.

OpenID Connect builds an authentication layer on top of OAuth 2.0.

Interview question

“Why would you choose a server-side session instead of JWT?”

A strong answer:

“I would prefer server-side sessions when revocation and centralized control are important and session infrastructure is acceptable. I would consider signed access tokens when independently deployed services need local validation and the token lifecycle can be managed safely.”


21. Observability

Monitoring is not enough.

Modern systems need three major observability signals:

  • Metrics
  • Logs
  • Traces

Metrics

Examples:

  • QPS
  • error rate
  • P50/P95/P99 latency
  • CPU
  • memory
  • queue depth
  • cache hit ratio
  • database connections

Logs

Useful for:

  • debugging
  • audit
  • incident investigation

Avoid logging:

  • passwords
  • secrets
  • authentication tokens
  • unnecessary personal data

Distributed Tracing

Tracing follows a request across services.

Request
  ├── API Gateway       8 ms
  ├── User Service     20 ms
  ├── Cache             3 ms
  ├── Order Service    70 ms
  └── Payment API      95 ms

This reveals where the latency actually went.


22. Production Operations

A production architecture includes more than runtime services.

The archive’s production-web architecture includes CI/CD, load balancing, CDN, APIs, data stores, queues, search, monitoring, and alerting.

A mature system also needs:

  • infrastructure as code
  • automated deployment
  • health checks
  • rollback
  • secrets management
  • capacity management
  • backups
  • incident response
  • runbooks
  • disaster recovery testing

Deployment Strategies

Strategy Advantage Trade-off
Rolling Simple, efficient Mixed versions
Blue-green Fast rollback Extra environment cost
Canary Limits blast radius Requires strong monitoring
A/B Experimentation More application complexity

The archive discusses blue-green, canary, and A/B deployment strategies and their respective trade-offs.


23. Infrastructure as Code

Infrastructure as Code treats infrastructure configuration as version-controlled code.

Typical benefits:

  • repeatability
  • reviewability
  • automation
  • environment consistency
  • disaster recovery
  • auditability

Typical tools include:

  • Terraform
  • CloudFormation
  • Ansible
  • GitOps workflows

Important distinction:

Containerization, orchestration, IaC, and GitOps solve different problems.

Containerization

Package application

Orchestration

Run and manage containers

Infrastructure as Code

Provision infrastructure

GitOps

Drive deployment/configuration from Git

24. Docker vs Kubernetes

The archive describes Docker as a containerization technology and Kubernetes as a cluster-level orchestration platform.

A more precise interview framing:

Docker / container runtime ecosystem

Useful for:

  • packaging applications
  • local development
  • reproducible environments
  • running containers

Kubernetes

Useful for:

  • scheduling
  • service discovery
  • scaling
  • rolling deployments
  • self-healing
  • workload orchestration

Do not say:

“Docker manages one container and Kubernetes manages many.”

Containers can run multiple workloads on a host.

Instead say:

“Containerization packages and isolates workloads; Kubernetes orchestrates containerized workloads across a cluster.”

Staff/Principal question

“Why Kubernetes?”

A strong answer might be:

“Only if the operational requirements justify it. If the workload is small and managed compute meets our requirements, Kubernetes may add unnecessary control-plane and platform complexity.”


25. Scalability

The archive identifies three important scalability bottlenecks:

  1. Centralized components
  2. High-latency components
  3. Tight coupling

It recommends principles such as:

  • statelessness
  • loose coupling
  • asynchronous processing
  • load balancing
  • caching
  • event-driven processing
  • sharding

Horizontal vs Vertical Scaling

Strategy Strength Limitation
Vertical Simple Hardware ceiling
Horizontal Elastic Distributed-system complexity

A system can scale horizontally only when its architecture permits it.


25.1 The 10× Question

When the interviewer says:

“Traffic increases 10×. What happens?”

Walk through the system.

10× Traffic

CDN capacity?

Gateway capacity?

Service instances?

Cache capacity?

Database QPS?

Connection pools?

Queue throughput?

Downstream dependencies?

Observability pipeline?

This is much stronger than saying:

“Add more servers.”


26. Bottleneck Analysis

A useful model is:

$$ System\ Throughput \leq \min(T_1,T_2,\ldots,T_n) $$

The slowest constrained component determines system throughput.

For example:

API        → 100K QPS
Cache      → 500K QPS
Service    → 150K QPS
Database   → 20K QPS
Queue      → 200K QPS

The database is the bottleneck.

Scaling the API from 100K to 300K QPS will not improve the end-to-end system.

Principal-level reasoning

Ask:

“Can I remove the bottleneck, move work elsewhere, reduce work, or change the consistency model?”

Possible strategies:

  • cache
  • batch
  • denormalize
  • partition
  • asynchronous processing
  • read replicas
  • workload isolation
  • precomputation

27. Cost Is a First-Class Architecture Constraint

A design can be technically excellent and economically irrational.

Consider:

$$ Total\ Cost = Compute + Storage + Network + Database + Observability + Operations $$

A Principal engineer evaluates:

  • peak vs average utilization
  • reserved capacity
  • autoscaling
  • storage tiering
  • data retention
  • cross-region traffic
  • cache cost
  • observability volume
  • engineering/operator cost

Cost Optimization Example

Suppose a system spends:

  • $40K compute
  • $20K database
  • $15K storage
  • $10K network
  • $15K observability

Total:

$$ 100K/month $$

A 30% reduction target means:

$$ 100K \times 0.30 = 30K/month $$

Do not randomly optimize.

Find the largest contributors first.

If compute is 40% of spend, a 25% compute reduction saves:

$$ 40K \times 0.25 = 10K/month $$

The rest can come from:

  • reducing telemetry volume
  • storage lifecycle policies
  • better caching
  • right-sizing
  • workload scheduling
  • reducing cross-region traffic

28. Operational Complexity Is a Real Cost

A useful Staff/Principal heuristic is:

$$ Total\ Cost = Infrastructure\ Cost + Operational\ Cost + Engineering\ Cost $$

A 10-service architecture may be cheaper in infrastructure than a monolith in some scenarios, but dramatically more expensive to operate.

Each additional distributed component introduces:

  • deployment complexity
  • monitoring
  • on-call burden
  • failure modes
  • network calls
  • security policies
  • capacity planning

Therefore:

Do not optimize for architectural sophistication. Optimize for the required system properties.


29. Monolith vs Microservices

Dimension Monolith Microservices
Initial complexity Lower Higher
Deployment Simple Independent
Scaling Coarse-grained Service-level
Data ownership Often shared Usually separated
Failure isolation Lower Potentially higher
Operational burden Lower Higher
Team autonomy Lower at large scale Higher
Distributed failure modes Fewer More

A modular monolith can be an excellent starting point.

Staff-level answer

“I would begin with strong module boundaries inside a monolith unless independent scaling, deployment, ownership, or failure isolation creates a compelling reason to split services.”


30. Architecture Trade-Offs

Every major design decision should answer:

  1. What problem are we solving?
  2. What alternatives exist?
  3. Why did we choose this option?
  4. What are we giving up?
  5. What happens at 10× scale?
  6. What happens during failure?
  7. What is the operational cost?
  8. How can we migrate later?

Trade-Off Table

Decision Option A Option B Primary trade-off
Service architecture Monolith Microservices Simplicity vs independence
Communication Sync Async Simplicity vs resilience
Storage SQL NoSQL Transactions vs flexible scaling
Cache Local Distributed Latency vs shared state
Consistency Strong Eventual Correctness vs availability/latency
Scaling Vertical Horizontal Simplicity vs elasticity
Deployment Blue-green Canary Rollback simplicity vs infrastructure efficiency
DR Single-region Multi-region Cost vs resilience
Search DB queries Search engine Simplicity vs search capability
Compute Managed Kubernetes Operational simplicity vs control

31. Practical Example — URL Shortener

Requirements

Functional:

  • Create short URL.
  • Redirect short URL.
  • Optional expiration.
  • Optional analytics.

NFR assumptions:

  • 100M redirects/day
  • 10M creates/day
  • 10× read/write ratio
  • P99 redirect latency < 100 ms
  • 99.99% availability

Scale

Redirect QPS:

$$ \frac{100M}{86,400} \approx 1,157\ QPS $$

Peak factor = 5:

$$ QPS_{peak} \approx 5,785 $$

This is not extreme scale.

A simple architecture may be sufficient:

flowchart LR
    Client --> CDN
    CDN --> LB
    LB --> API
    API --> Cache
    Cache --> DB
    API --> Queue
    Queue --> Analytics

Key design decisions

  • Cache hot short codes.
  • Use a unique ID generation strategy.
  • Store mappings durably.
  • Make analytics asynchronous.
  • Protect the database from cache stampedes.
  • Use TTL if links expire.

Staff insight

Do not immediately introduce:

  • 50 microservices
  • Kafka
  • multi-region active-active
  • sharded databases

unless the requirements justify them.


32. Practical Example — Notification System

A notification system is naturally asynchronous.

flowchart LR
    Producer --> API
    API --> Queue
    Queue --> Router
    Router --> Email
    Router --> SMS
    Router --> Push
    Email --> Provider
    SMS --> Provider
    Push --> Provider
    Router --> StatusStore

Important design questions:

  • How many notifications/sec?
  • What delivery latency is required?
  • Is ordering required?
  • How many retries?
  • What happens when a provider is unavailable?
  • Are duplicates acceptable?
  • How do we handle provider rate limits?
  • How long do we retain delivery history?

Staff/Principal insight

The hardest problem is often not sending the first notification.

It is reliably handling:

  • retries
  • duplicates
  • provider failures
  • backpressure
  • rate limits
  • tenant isolation
  • dead-letter queues
  • observability

33. Practical Example — RAG / LLM System

Modern AI systems are also distributed systems.

A production RAG system may look like:

flowchart LR
    User --> Gateway
    Gateway --> Auth
    Gateway --> RAGService
    RAGService --> QueryRewrite
    QueryRewrite --> Retriever
    Retriever --> VectorDB
    Retriever --> MetadataDB
    Retriever --> Reranker
    Reranker --> PromptBuilder
    PromptBuilder --> LLM
    LLM --> Guardrails
    Guardrails --> User
    Documents --> Chunker
    Chunker --> Embedder
    Embedder --> VectorDB

The archive identifies embeddings, RAG libraries, backend frameworks, data/retrieval stores, and foundation models as major layers in an open-source AI stack.

AI-specific system-design dimensions

  • token throughput
  • model latency
  • context-window constraints
  • retrieval latency
  • vector search QPS
  • embedding cost
  • inference cost
  • GPU utilization
  • model fallback
  • prompt caching
  • semantic caching
  • tenant isolation
  • evaluation
  • hallucination monitoring

A useful latency equation is:

$$ T_{total}

T_{auth} + T_{retrieval} + T_{reranking} + T_{prompt} + T_{inference} + T_{postprocess} $$

If LLM inference dominates, optimizing database latency from 20 ms to 10 ms may have little user-visible impact.


34. Performance Debugging Framework

When an API is slow, do not guess.

The archive recommends a systematic approach involving network, backend code, database, external APIs, and infrastructure.

Use:

1. Measure

2. Locate the bottleneck

3. Quantify its contribution

4. Fix

5. Re-measure

Check:

Network

  • DNS
  • TLS
  • payload size
  • compression
  • CDN

Application

  • CPU
  • locks
  • blocking calls
  • thread pools
  • garbage collection
  • serialization

Database

  • indexes
  • query plans
  • N+1 queries
  • connection pools
  • locks
  • hot partitions

External dependencies

  • latency
  • timeout
  • retry behavior
  • rate limits

Infrastructure

  • CPU
  • memory
  • autoscaling
  • network saturation
  • container limits

Senior-level principle

Measure first. Optimize second.


35. Failure-Mode-First Design

Before finalizing an architecture, ask:

“How does this system fail?”

For every major dependency:

Dependency

What if it is slow?

What if it is unavailable?

What if it returns bad data?

What if requests are duplicated?

What if the network partitions?

What if traffic increases 10×?

This produces much stronger designs than simply adding components.


36. The Staff/Principal Deep-Dive Pattern

When the interviewer points to one component, use:

Purpose

Scale

Data / State

Concurrency

Failure Modes

Consistency

Performance

Security

Observability

Capacity

Trade-offs

Example:

“Let’s deep dive into the database.”

A strong response:

  1. What queries dominate?
  2. What is the read/write ratio?
  3. What is the data volume?
  4. What indexes are required?
  5. What is the transaction boundary?
  6. What is the partition key?
  7. What is the replication strategy?
  8. What happens when the primary fails?
  9. What happens at 10× writes?
  10. What is the cost?

37. Architectural Evolution

Staff/Principal engineers think in phases, not only the final architecture.

Phase 1 — Simple

Client

API

SQL Database

Phase 2 — Scale Reads

Client

LB

Stateless Services

Cache

DB + Read Replicas

Phase 3 — Decouple Work

Services

Queue

Workers

Phase 4 — Partition

Service

Shard Router

Shard 1 / Shard 2 / Shard 3 / ...

Phase 5 — Multi-Region

              Global Router
               /         \
          Region A     Region B
             ↓            ↓
        Services       Services
             ↓            ↓
          Data Plane / Replication

Do not build Phase 5 on Day 1 unless the requirements demand it.


38. Common Staff/Principal-Level Interview Mistakes

38.1 Jumping into Architecture

Bad:

“We’ll use Kubernetes, Kafka, Redis, Cassandra, and Elasticsearch.”

Better:

“Let me clarify the workload and availability requirements first.”


38.2 Over-Engineering Too Early

Adding distributed systems components before proving the need creates unnecessary complexity.


38.3 Ignoring Scale Estimation

Saying “millions of users” is not capacity planning.

Estimate:

  • QPS
  • peak QPS
  • storage
  • bandwidth
  • cache
  • replication
  • capacity headroom

38.4 Choosing Technology Without a Reason

Bad:

“Use Cassandra because it scales.”

Better:

“I would consider a distributed key-value store if the access pattern is primarily key-based and we need high write throughput across partitions.”


38.5 Ignoring Failure Scenarios

A diagram without failure behavior is incomplete.

Ask:

  • What if the database fails?
  • What if cache fails?
  • What if the queue is delayed?
  • What if a region fails?
  • What if the dependency becomes slow?

38.6 Ignoring Operational Complexity

Every service creates operational obligations.

Ask:

  • Who owns it?
  • How is it deployed?
  • How is it monitored?
  • How is it debugged?
  • How is it upgraded?
  • How does it fail?

38.7 Ignoring Cost

A design that meets latency but costs 10× the business budget is not a successful architecture.


38.8 Focusing Only on Components

A Staff engineer explains relationships and trade-offs, not just boxes.


38.9 Not Explaining Evolution

A mature answer explains:

“This is what I would build today, and this is what I would change at 10× scale.”


39. Staff/Principal Interview Questions

Requirements

  • What assumptions are you making?
  • Which requirements are hard constraints?
  • What would you remove from V1?
  • What requirement changes your architecture the most?

Scale

  • What is average QPS?
  • What is peak QPS?
  • What is the read/write ratio?
  • How much data after three years?
  • What is the bandwidth requirement?
  • What happens at 10×?

Architecture

  • Why this architecture?
  • Why not a monolith?
  • Why not microservices?
  • Which component is the bottleneck?
  • What is the critical path?

Data

  • Why SQL?
  • Why NoSQL?
  • What is the partition key?
  • How do you handle hot partitions?
  • What is your consistency model?
  • What happens during a database failure?

Reliability

  • What is your SLA?
  • What is your RTO/RPO?
  • How do you survive a region failure?
  • How do retries affect the system?
  • How do you prevent cascading failures?

Performance

  • What is your P99 latency?
  • Where is the latency budget spent?
  • How do you debug a slow API?
  • What happens when utilization reaches 90%?

Security

  • How are users authenticated?
  • How are permissions enforced?
  • How are secrets managed?
  • How do you prevent abuse?
  • How do you isolate tenants?

Operations

  • How do you deploy?
  • How do you roll back?
  • What metrics do you monitor?
  • How do you detect a silent failure?
  • How do you perform disaster recovery testing?

Cost

  • What is the largest cost?
  • How would you reduce cost by 30%?
  • What would you sacrifice to reduce cost?
  • Which components can scale down during off-peak periods?

Evolution

  • What happens after three years?
  • How would you migrate the database?
  • How would you introduce a new API version?
  • How would you split a monolith?
  • How would you migrate to multi-region?

40. The Staff/Principal Answer Template

When you need a concise interview structure, use:

1. Clarify requirements
2. State assumptions
3. Estimate scale
4. Define APIs
5. Define data model
6. Draw the simplest viable architecture
7. Identify the critical path
8. Deep dive into the bottleneck
9. Explain consistency
10. Explain failure handling
11. Explain security
12. Explain observability
13. Estimate capacity and cost
14. Discuss trade-offs
15. Explain 10× growth
16. Explain architectural evolution

A strong opening sounds like:

“I’ll first clarify the functional and non-functional requirements. Then I’ll estimate peak traffic and data volume because those numbers determine whether we need caching, replication, partitioning, or asynchronous processing. I’ll propose a simple baseline architecture, then deep-dive into the highest-risk components and failure modes.”

That statement alone signals structured thinking.


41. Final Staff/Principal Mental Model

The most important transition is:

Senior Engineer

"How do I build this?"

to:

Staff Engineer

"What architecture best satisfies the constraints?"

to:

Principal Engineer

"What is the simplest architecture that satisfies today's
requirements, remains economically viable, survives realistic
failures, and gives the organization a credible path to evolve?"

A high-quality system-design answer therefore optimizes across:

$$ Architecture\ Quality = f( Correctness, Scalability, Reliability, Latency, Security, Operability, Cost, Evolution ) $$

There is no universally best architecture.

There is only an architecture that is appropriate for the requirements, constraints, failure model, and stage of the system.


42. Staff/Principal Interview Checklist

Use this checklist before finishing any system-design interview.

Requirements

  • Functional requirements clarified
  • Non-functional requirements quantified
  • Scope explicitly defined
  • Assumptions stated

Scale

  • DAU / users estimated
  • Average QPS estimated
  • Peak QPS estimated
  • Read/write ratio estimated
  • Storage growth estimated
  • Bandwidth estimated
  • Cache memory estimated
  • Capacity headroom considered

API

  • API style justified
  • Request/response contracts defined
  • Pagination considered
  • Idempotency considered
  • Versioning considered
  • Rate limiting considered
  • Authentication/authorization considered

Data

  • Data model defined
  • Storage selected based on workload
  • Indexes considered
  • Replication strategy defined
  • Partitioning strategy considered
  • Consistency model justified

Architecture

  • Simple baseline architecture drawn
  • Statelessness considered
  • Load balancing considered
  • Caching considered
  • Async processing considered
  • Search requirements separated from system of record

Reliability

  • Failure modes identified
  • Timeouts defined
  • Retry strategy defined
  • Circuit breaking considered
  • Backpressure considered
  • RTO defined
  • RPO defined
  • Regional failure considered

Security

  • TLS
  • Authentication
  • Authorization
  • Input validation
  • Rate limiting
  • Secrets management
  • Encryption at rest
  • Audit logging
  • Tenant isolation

Observability

  • Metrics
  • Logs
  • Distributed traces
  • SLOs
  • Alerts
  • Capacity dashboards

Cost

  • Compute cost
  • Storage cost
  • Network cost
  • Database cost
  • Observability cost
  • Operational complexity
  • 30% cost-reduction strategy

Trade-offs

  • Alternatives discussed
  • Decision rationale explained
  • Explicit drawbacks acknowledged
  • Failure behavior explained
  • 10× growth discussed
  • Architecture evolution discussed

43. The One-Page Interview Summary

                    SYSTEM DESIGN

          ┌──────────────┴──────────────┐
          │                             │
     REQUIREMENTS                     SCALE
          │                             │
   Functional + NFRs          QPS / Storage / Bandwidth
          │                             │
          └──────────────┬──────────────┘

                  API + DATA MODEL

                 HIGH-LEVEL DESIGN

          ┌──────────────┼──────────────┐
          ↓              ↓              ↓
       CACHE         DATABASE        QUEUE
          │              │              │
          └──────────────┼──────────────┘

                 BOTTLENECK ANALYSIS

       ┌─────────────────┼─────────────────┐
       ↓                 ↓                 ↓
   Reliability        Security        Observability
       │                 │                 │
       └─────────────────┼─────────────────┘

                    COST + CAPACITY

                    TRADE-OFFS

                 10× SCALE / DR

                    EVOLUTION

Final Interview Principle

Do not try to impress the interviewer with the number of technologies you know. Impress them with the quality of your decisions.

The strongest Staff/Principal system-design candidate consistently demonstrates:

  1. Structured thinking
  2. Quantitative reasoning
  3. Clear communication
  4. Explicit trade-offs
  5. Failure-mode awareness
  6. Operational maturity
  7. Cost awareness
  8. Long-term architectural judgment

That is the difference between drawing an architecture and owning the architecture.