Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

Guides › Software Engineering & System Design

System Design: Beginner to Advanced

Learn system design, scalability, caching, databases, APIs, and distributed systems with practical examples and interview tips.

🏗️ System Design: Beginner to Advanced

System design ka matlab hai kisi software application ki architecture plan karna, taaki woh real-world users, data, traffic, failures aur future growth ko handle kar sake. Is guide mein hum fundamentals se advanced distributed systems tak step-by-step seekhenge.

1. What Is System Design?

System design defines how different components of a software system work together.

A typical system may contain:

Goals of system design

A well-designed system should be:

There is rarely one perfect design. Engineering means balancing trade-offs.

2. Functional and Non-Functional Requirements

Functional requirements

Describe what the system must do.

Example for a URL shortener:

Non-functional requirements

Describe how well the system should perform.

Examples:

Requirement checklist

Before designing, ask:

  1. Who are the users?
  2. What are the main use cases?
  3. What is the expected traffic?
  4. How much data will be stored?
  5. What are the latency targets?
  6. What availability is required?
  7. Is data loss acceptable?
  8. Are there security or compliance requirements?
  9. What is the budget?
  10. Which features are explicitly out of scope?

3. Capacity Estimation

Capacity estimation provides rough numbers to guide architecture decisions. Estimates are not guarantees; validate them with measurement and load testing.

Example: daily requests

Assume a service receives 10 million requests per day.

Average requests per second:

Average RPS = 10,000,000 / 86,400 ≈ 116

If peak traffic is five times the average:

Peak RPS ≈ 580

Design for expected peaks, bursts, retries and growth rather than only the daily average.

Storage estimation

Suppose the system creates 2 million records daily, with an average stored record size of 1 KB.

Daily raw storage ≈ 2 GB

For one year:

2 GB × 365 ≈ 730 GB

Actual storage may be higher because of indexes, replication, metadata, backups and logs.

Bandwidth estimation

Bandwidth depends on request and response sizes.

Approximate bandwidth = requests per second × average bytes per response.

Convert bytes per second to bits per second by multiplying by 8.

Useful estimation concepts

4. Latency, Throughput and Performance

Latency

Time taken to complete a request.

Common measurements:

Tail latency matters because a small percentage of very slow requests can harm user experience.

Throughput

Amount of work completed per unit of time, such as requests per second or messages per second.

Performance optimization process

  1. Establish a baseline.
  2. Measure using profiling and monitoring.
  3. Identify the bottleneck.
  4. Make one targeted change.
  5. Repeat load tests.
  6. Compare results and cost.

Avoid optimizing based only on assumptions.

5. Basic Client-Server Architecture

A simple request flow:

  1. User interacts with a client.
  2. Client sends an HTTP request.
  3. DNS resolves the domain.
  4. Network traffic reaches the server or load balancer.
  5. Application validates the request.
  6. Application reads or writes data.
  7. Server returns an HTTP response.
  8. Client displays the result.

A monolithic application may contain multiple modules deployed as one unit. This is often a sensible starting point for small and medium applications.

6. API Design

An API defines how components communicate.

REST example

HTTP method guidance

Good API practices

Example response

{
  "id": "url_123",
  "shortCode": "aB92x",
  "shortUrl": "https://example.com/aB92x"
}

7. Load Balancing

A load balancer distributes requests across multiple servers.

Why use it?

Common algorithms

Layer 4 versus Layer 7

A load balancer does not automatically fix slow code, database bottlenecks or poor query design.

8. Vertical and Horizontal Scaling

Vertical scaling

Increase CPU, memory or storage on one machine.

Advantages:

Disadvantages:

Horizontal scaling

Add more machines or instances.

Advantages:

Challenges:

Stateless application servers are generally easier to scale horizontally.

9. Caching

A cache stores frequently accessed data in a faster storage layer.

Examples include in-memory caches and distributed caches.

Common caching patterns

Cache-aside

  1. Application checks the cache.
  2. On a miss, it reads the database.
  3. It places the result in the cache.
  4. It returns the result.

Write-through

Write-behind

Cache challenges

Never assume that cached data is always current. Decide how stale data may be and what happens when the cache is unavailable.

10. Database Design and Selection

Relational databases

Examples: PostgreSQL and MySQL.

Best suited to:

NoSQL databases

Categories include:

Choose based on access patterns, consistency, query needs, operational maturity and scale—not popularity alone.

Important database concepts

Indexes can accelerate reads but increase storage and write overhead.

11. Replication and Sharding

Replication

Copies data across database nodes.

Uses:

Potential issue: replicas may lag behind the primary, so reads may return stale data.

Sharding

Splits data across multiple partitions or nodes.

Possible shard keys:

A poor shard key may create hot partitions or uneven distribution.

Plan for rebalancing, cross-shard queries, migrations and shard failures.

12. CAP Theorem and Consistency

The CAP theorem concerns distributed data systems when a network partition occurs. In that situation, a system must trade off between consistency and availability.

CAP does not simply mean a system can permanently choose only two of three properties under all conditions. The trade-off becomes important during a partition.

Consistency models

Choose the weakest model that safely meets the product's requirements, because stronger guarantees can add latency and coordination costs.

13. Message Queues and Asynchronous Processing

A queue allows a producer to publish work that consumers process later.

Examples: order confirmation emails, report generation, image processing and analytics events.

Benefits

Important concepts

Consumers should usually be idempotent because messages may be delivered more than once.

Do not claim exactly-once processing unless the complete system's semantics actually provide it. Often the practical design is at-least-once delivery plus deduplication and idempotent processing.

14. Monoliths, Microservices and Modular Architecture

Monolith

One deployable application containing multiple modules.

Advantages:

Disadvantages:

Microservices

A system composed of independently deployable services communicating over defined interfaces.

Advantages:

Challenges:

Start with a modular monolith when it meets requirements. Split services when clear organizational or technical benefits justify the additional complexity.

15. Fault Tolerance and Resilience

A resilient system expects components to fail.

Essential patterns

Retries can amplify outages. Apply retry budgets, deadlines and idempotency where needed.

16. Event-Driven Architecture

Services communicate through events such as OrderCreated or PaymentSucceeded.

Benefits

Challenges

Use the transactional outbox pattern when a database change and event publication must stay coordinated. Consumers should validate event schemas and handle duplicates safely.

17. Security by Design

Security is a system requirement, not a final add-on.

Do not log passwords, access tokens, private keys or unnecessary personal information.

18. Observability

Observability helps explain what is happening inside a system.

Three pillars

Useful indicators

Define service-level indicators (SLIs), service-level objectives (SLOs) and, where appropriate, service-level agreements (SLAs).

Alerts should be actionable and tied to user impact where possible.

19. Deployment and Infrastructure

Common deployment approaches:

Use:

Canary and blue-green deployments reduce risk but still require monitoring and rollback planning.

20. Practical Design: URL Shortener

Requirements

Functional:

Non-functional:

High-level architecture

Client
  |
DNS / CDN (optional)
  |
Load Balancer
  |
URL API Service
  |------------- Cache
  |
Database
  |
Analytics Event Queue
  |
Background Workers

Request flow

Creation:

  1. Validate the submitted URL.
  2. Apply abuse and safety checks.
  3. Generate a unique code.
  4. Store code-to-URL mapping.
  5. Return the short URL.

Redirect:

  1. Receive the code.
  2. Check cache.
  3. Query the database on a cache miss.
  4. Verify expiration and policy.
  5. Return an appropriate redirect.
  6. Record analytics asynchronously if appropriate.

Design considerations

21. Other Common System Design Problems

Practice designing:

For each, identify requirements, APIs, data models, bottlenecks, failures and trade-offs.

22. System Design Interview Framework

Use this repeatable process:

  1. Clarify requirements.
  2. Define scope and assumptions.
  3. Estimate traffic and storage.
  4. Identify APIs and core data models.
  5. Draw the high-level architecture.
  6. Explain request and data flows.
  7. Identify bottlenecks.
  8. Scale critical components.
  9. Discuss consistency and failure handling.
  10. Cover security and observability.
  11. Explain trade-offs and alternatives.

Do not immediately jump to Kafka, Kubernetes or dozens of microservices. Begin with the simplest design that meets the requirements.

23. Common Mistakes

24. Practice Plan

Week 1: Fundamentals

Week 2: Scaling

Week 3: Distributed systems

Week 4: Design practice

For every design, document requirements, architecture, failure scenarios and trade-offs.

25. Final Checklist

Conclusion

System design is a process of making informed decisions under constraints. Learn fundamentals first, measure real bottlenecks, understand failure modes and choose the simplest architecture that meets the requirements.

More guides