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:
- Client applications: web, mobile, desktop.
- DNS and networking.
- Load balancers and API gateways.
- Application servers.
- Databases and caches.
- Message queues and background workers.
- File and object storage.
- Monitoring, logging and alerting systems.
Goals of system design
A well-designed system should be:
- Reliable: provides correct service consistently.
- Available: remains accessible when expected.
- Scalable: handles increasing users and workload.
- Maintainable: easy to understand and modify.
- Secure: protects data and access.
- Cost-effective: meets requirements within budget.
- Observable: exposes enough information to diagnose problems.
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:
- Accept a long URL.
- Generate a short code.
- Redirect users to the original URL.
- Allow authorized users to view click analytics.
- Optionally support expiration dates and custom aliases.
Non-functional requirements
Describe how well the system should perform.
Examples:
- Support 1 million daily active users.
- Keep redirect latency low.
- Maintain high availability.
- Protect users against malicious links.
- Retain analytics for a defined period.
Requirement checklist
Before designing, ask:
- Who are the users?
- What are the main use cases?
- What is the expected traffic?
- How much data will be stored?
- What are the latency targets?
- What availability is required?
- Is data loss acceptable?
- Are there security or compliance requirements?
- What is the budget?
- 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
- Average traffic versus peak traffic.
- Read-to-write ratio.
- Data retention period.
- Growth rate.
- Replication factor.
- Compression ratio.
- Cache hit ratio.
- Safety margin and headroom.
4. Latency, Throughput and Performance
Latency
Time taken to complete a request.
Common measurements:
- p50: median latency.
- p95: 95% of requests complete within this duration.
- p99: 99% complete within this duration.
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
- Establish a baseline.
- Measure using profiling and monitoring.
- Identify the bottleneck.
- Make one targeted change.
- Repeat load tests.
- Compare results and cost.
Avoid optimizing based only on assumptions.
5. Basic Client-Server Architecture
A simple request flow:
- User interacts with a client.
- Client sends an HTTP request.
- DNS resolves the domain.
- Network traffic reaches the server or load balancer.
- Application validates the request.
- Application reads or writes data.
- Server returns an HTTP response.
- 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
POST /api/urls— create a short URL.GET /{code}— redirect to the destination.GET /api/urls/{id}/analytics— retrieve analytics.
HTTP method guidance
- GET: retrieve a resource.
- POST: create a resource or trigger an operation.
- PUT: replace a resource.
- PATCH: partially update a resource.
- DELETE: delete a resource.
Good API practices
- Use consistent naming.
- Validate all input.
- Return appropriate HTTP status codes.
- Document request and response schemas.
- Apply authentication and authorization.
- Use pagination for large collections.
- Version APIs when necessary.
- Define rate limits.
- Use idempotency keys for retryable payment or creation operations where appropriate.
- Avoid exposing internal errors or secrets.
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?
- Spread traffic.
- Improve availability.
- Support horizontal scaling.
- Perform health checks.
- Remove unhealthy instances from rotation.
Common algorithms
- Round robin: distributes requests in order.
- Weighted round robin: sends more traffic to higher-capacity servers.
- Least connections: favors servers with fewer active connections.
- Consistent hashing: maps keys to servers with reduced remapping when membership changes.
Layer 4 versus Layer 7
- Layer 4 balancing uses transport-level information such as TCP or UDP.
- Layer 7 balancing can route based on HTTP paths, headers, hostnames or other application data.
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:
- Simple to implement.
- Fewer distributed-system concerns.
Disadvantages:
- Hardware limits.
- Potentially expensive upgrades.
- A single machine may remain a failure point.
Horizontal scaling
Add more machines or instances.
Advantages:
- Can support larger workloads.
- Allows redundancy.
- Can scale incrementally.
Challenges:
- Load distribution.
- Shared state.
- Network failures.
- Coordination and consistency.
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
- Application checks the cache.
- On a miss, it reads the database.
- It places the result in the cache.
- It returns the result.
Write-through
- Writes update the cache and underlying data store according to the chosen implementation.
Write-behind
- Writes reach the cache first and are persisted asynchronously. This requires careful durability and recovery design.
Cache challenges
- Expiration and TTL.
- Stale data.
- Cache invalidation.
- Cache stampedes.
- Hot keys.
- Memory limits.
- Cold starts.
- Cache failure behavior.
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:
- Structured data.
- Relationships and joins.
- Transactions.
- Strong integrity constraints.
NoSQL databases
Categories include:
- Document stores.
- Key-value stores.
- Wide-column stores.
- Graph databases.
Choose based on access patterns, consistency, query needs, operational maturity and scale—not popularity alone.
Important database concepts
- Primary keys and foreign keys.
- Indexes.
- Normalization and denormalization.
- Transactions and isolation.
- Query plans.
- Connection pooling.
- Replication.
- Partitioning and sharding.
- Backups and recovery.
Indexes can accelerate reads but increase storage and write overhead.
11. Replication and Sharding
Replication
Copies data across database nodes.
Uses:
- High availability.
- Disaster recovery.
- Read scaling.
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:
- User ID.
- Tenant ID.
- Geographic region.
- Hash of a record ID.
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.
- Consistency: operations behave according to the system's specified single-copy consistency model.
- Availability: requests to non-failing nodes receive a response.
- Partition tolerance: the system continues operating despite communication failures between nodes.
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
- Strong consistency.
- Eventual consistency.
- Read-your-writes consistency.
- Monotonic reads.
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
- Decouples services.
- Smooths traffic spikes.
- Enables retries.
- Moves slow tasks out of request paths.
Important concepts
- Producer and consumer.
- Queue depth.
- Acknowledgements.
- Retry policies.
- Dead-letter queues.
- Consumer groups.
- Ordering guarantees.
- Duplicate delivery.
- Backpressure.
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:
- Simple deployment.
- Easier local development.
- Straightforward transactions within one database.
Disadvantages:
- Large codebases can become tightly coupled.
- Scaling individual modules may be difficult.
- Releases may become risky as the application grows.
Microservices
A system composed of independently deployable services communicating over defined interfaces.
Advantages:
- Independent deployment and scaling.
- Clear service ownership.
- Potential technology flexibility.
Challenges:
- Network failures.
- Distributed transactions.
- Observability complexity.
- Operational overhead.
- Version compatibility.
- Data consistency.
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
- Timeouts: prevent requests from waiting indefinitely.
- Retries: retry transient failures with limits.
- Exponential backoff: increase delay between retries.
- Jitter: randomize delays to reduce synchronized retries.
- Circuit breaker: temporarily stop calls to an unhealthy dependency.
- Bulkhead: isolate resources so one failing component does not exhaust everything.
- Rate limiting: control incoming workload.
- Graceful degradation: preserve core functionality when optional features fail.
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
- Loose coupling.
- Asynchronous workflows.
- Easier integration between independent components.
Challenges
- Event ordering.
- Duplicate delivery.
- Schema evolution.
- Debugging across services.
- Eventual consistency.
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.
- Authenticate users and services.
- Authorize each sensitive operation.
- Apply least privilege.
- Encrypt traffic using TLS.
- Encrypt sensitive stored data where appropriate.
- Store secrets in a secret manager.
- Validate and normalize input.
- Protect against injection, SSRF and broken access control.
- Rate-limit abusive traffic.
- Audit sensitive actions.
- Patch dependencies.
- Back up data and test recovery.
- Define data retention and deletion policies.
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
- Metrics: numerical trends, such as request rate and error rate.
- Logs: event details useful for diagnosis.
- Traces: request paths across multiple services.
Useful indicators
- Traffic.
- Errors.
- Latency.
- Saturation of CPU, memory, connections and queues.
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:
- Virtual machines.
- Containers.
- Managed application platforms.
- Serverless functions.
- Kubernetes for suitable orchestration needs.
Use:
- Infrastructure as Code.
- Automated tests.
- CI/CD pipelines.
- Health checks.
- Rollback procedures.
- Staged rollouts.
- Feature flags.
- Configuration separated from application code.
Canary and blue-green deployments reduce risk but still require monitoring and rollback planning.
20. Practical Design: URL Shortener
Requirements
Functional:
- Create a short URL.
- Redirect to the original URL.
- Support optional expiration.
- Collect basic analytics.
Non-functional:
- Low redirect latency.
- High availability.
- Unique short codes.
- Protection against malicious links.
High-level architecture
Client
|
DNS / CDN (optional)
|
Load Balancer
|
URL API Service
|------------- Cache
|
Database
|
Analytics Event Queue
|
Background Workers
Request flow
Creation:
- Validate the submitted URL.
- Apply abuse and safety checks.
- Generate a unique code.
- Store code-to-URL mapping.
- Return the short URL.
Redirect:
- Receive the code.
- Check cache.
- Query the database on a cache miss.
- Verify expiration and policy.
- Return an appropriate redirect.
- Record analytics asynchronously if appropriate.
Design considerations
- Use a database uniqueness constraint for codes.
- Handle collisions safely.
- Decide between random codes and encoded IDs.
- Prevent open-redirect abuse and malicious destinations.
- Avoid making analytics a critical dependency for redirects.
- Define deletion, expiration and retention behavior.
21. Other Common System Design Problems
Practice designing:
- Chat application.
- News feed.
- Notification service.
- Video streaming platform.
- File storage service.
- Ride-sharing service.
- E-commerce checkout.
- Search autocomplete.
- Ticket booking system.
- Metrics and logging platform.
For each, identify requirements, APIs, data models, bottlenecks, failures and trade-offs.
22. System Design Interview Framework
Use this repeatable process:
- Clarify requirements.
- Define scope and assumptions.
- Estimate traffic and storage.
- Identify APIs and core data models.
- Draw the high-level architecture.
- Explain request and data flows.
- Identify bottlenecks.
- Scale critical components.
- Discuss consistency and failure handling.
- Cover security and observability.
- 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
- Designing before clarifying requirements.
- Ignoring peak traffic.
- Choosing technology because it is fashionable.
- Treating cache data as always correct.
- Ignoring database indexes and query plans.
- Adding microservices too early.
- Retrying every failure without limits.
- Forgetting security and data retention.
- Ignoring disaster recovery.
- Focusing on architecture diagrams without explaining trade-offs.
24. Practice Plan
Week 1: Fundamentals
- HTTP, DNS, TCP, APIs.
- Latency, throughput and capacity estimation.
- Relational database design.
Week 2: Scaling
- Load balancing.
- Caching.
- Replication and sharding.
- Rate limiting.
Week 3: Distributed systems
- Queues and event-driven systems.
- Consistency.
- Fault tolerance.
- Observability.
Week 4: Design practice
- URL shortener.
- Chat application.
- Notification service.
- Video platform.
For every design, document requirements, architecture, failure scenarios and trade-offs.
25. Final Checklist
- Functional requirements are clear.
- Non-functional requirements are measurable.
- Capacity assumptions are documented.
- APIs and data models are defined.
- Database access patterns are understood.
- Scaling bottlenecks are identified.
- Failure and recovery paths are considered.
- Security and privacy are addressed.
- Metrics, logs and traces are planned.
- Costs and trade-offs are explained.
- The design has been validated through tests or prototypes.
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
- How to Use Codify: A 7-Day Start Plan — New here? Pick a roadmap, make a study plan, start the DSA sheet, revise with notes, practise for placements and test yourself — one step a day, then a daily routine.
- Infosys Preparation Guide: Online Test, Pseudocode and Interview — Roles (SE, DSE, SP), what each section of the Infosys online test checks, how to crack pseudocode and reasoning, a 4-week plan and the interview.
- Wipro Elite NLTH Preparation: Aptitude, Essay and Coding — The Wipro fresher test round by round — quant, logical and verbal, the written essay, two coding problems — plus a 3-week plan and interview tips.
- Accenture Preparation Guide: Cognitive, Technical, Coding and Communication — Every Accenture round explained — cognitive, MS Office/networking/cloud technical MCQs, pseudocode, coding and the spoken-English test — with a 4-week plan.