| SAML - Security Assertion Markup Language :👈 | 👉:Terms Of Use/Disclaimer |
System Design |
System Design – Complete Guide
1. What Is System Design?
System Design is the process of defining the architecture, components, technologies, databases, communication mechanisms, and infrastructure required to build a software system.
It explains how different parts of an application communicate and work together to satisfy functional and non-functional requirements.
In simple words, system design answers these questions:
- What components do we need?
- How will users access the application?
- Where will we store data?
- How will different services communicate?
- How will the application handle millions of users?
- How will we protect the application?
- How will we recover if something fails?
2. Real-World Example
Consider an application similar to Amazon.
A customer should be able to:
- Register and log in.
- Search for products.
- View product details.
- Add products to a cart.
- Place an order.
- Make payments.
- Track deliveries.
System design determines how these features are implemented and how their components communicate.
3. Why Is System Design Important?
- Scalability: Supports increasing numbers of users.
- Performance: Provides faster responses.
- Availability: Keeps the application accessible.
- Reliability: Handles failures gracefully.
- Security: Protects users and business data.
- Maintainability: Makes future changes easier.
- Cost optimization: Uses infrastructure efficiently.
4. Types of System Design
4.1 High-Level Design (HLD)
High-Level Design describes the overall architecture of the application.
It focuses on major components and their interactions.
It generally includes:
- Application architecture.
- Microservices or monolithic architecture.
- Database selection.
- API Gateway.
- Load balancers.
- Caching.
- Message queues.
- Cloud infrastructure.
4.2 Low-Level Design (LLD)
Low-Level Design explains the internal implementation of individual components.
It generally includes:
- Classes and interfaces.
- Methods and responsibilities.
- Design patterns.
- Database tables and relationships.
- API request and response structures.
- Validation and business logic.
HLD vs LLD
| High-Level Design | Low-Level Design |
|---|---|
| Overall architecture | Internal implementation |
| Major components | Classes and methods |
| Service communication | Object communication |
| Database technology selection | Table and index design |
| Architecture diagrams | Class and sequence diagrams |
5. Functional and Non-Functional Requirements
5.1 Functional Requirements
Functional requirements describe what the application must do.
Example for an e-commerce application:
- Users can register and log in.
- Users can search products.
- Users can add products to the cart.
- Users can place orders.
- Users can make payments.
5.2 Non-Functional Requirements
Non-functional requirements describe how well the application should work.
- Performance.
- Scalability.
- Availability.
- Security.
- Reliability.
- Maintainability.
- Disaster recovery.
6. Basic Architecture of a Web Application
A typical web application contains the following layers:
Explanation:
- User sends a request through a browser or mobile application.
- Load balancer distributes incoming traffic.
- Web application receives the request.
- Business layer executes business rules.
- Cache is checked for frequently requested data.
- Database is accessed when required.
- Response is returned to the user.
7. Important Components of System Design
7.1 Client
The client is the application used by the end user.
Examples:
- Web browser.
- Android application.
- iOS application.
- Desktop application.
7.2 DNS (Domain Name System)
DNS converts domain names into IP addresses.
Example:
www.example.com
|
v
DNS Lookup
|
v
Server IP Address
7.3 Load Balancer
A load balancer distributes incoming requests across multiple application instances.
Example:
Load Balancer
|
+--------+--------+
| | |
v v v
Server 1 Server 2 Server 3
Benefits:
- Distributes traffic.
- Improves availability.
- Prevents one server from becoming overloaded.
- Supports horizontal scaling.
7.4 API Gateway
An API Gateway acts as a single entry point for multiple backend services.
Example:
Client
|
v
API Gateway
|
+--------+--------+
| | |
v v v
User Product Order
Service Service Service
Common responsibilities:
- Request routing.
- Authentication.
- Rate limiting.
- Request validation.
- API versioning.
- Logging and monitoring.
In .NET, YARP can be used to build a reverse proxy and API gateway.
7.5 Application Server
An application server executes application logic and processes requests.
Examples:
- ASP.NET Core Web API.
- Java Spring Boot.
- Node.js applications.
7.6 Database
A database stores application data permanently or for a defined retention period.
Examples:
- SQL Server.
- PostgreSQL.
- MySQL.
- MongoDB.
7.7 Cache
Cache stores frequently accessed data in a faster storage layer.
Examples:
- Redis.
- Memcached.
- In-memory cache.
Example: Product categories can be cached to reduce repeated database queries.
7.8 Message Queue
A message queue enables asynchronous communication between application components.
Examples:
- RabbitMQ.
- Azure Service Bus.
- Amazon SQS.
Example:
Order Service
|
v
Message Queue
|
+-----+-----+
| |
v v
Email Service Inventory Service
After an order is placed, the Order Service can publish an event. Other services process it independently.
8. Monolithic Architecture
In a monolithic architecture, multiple application features are implemented and deployed as one application.
E-Commerce Application
|
+---------+---------+
| | |
v v v
Users Products Orders
| | |
+---------+---------+
|
Database
Advantages:
- Simple to develop initially.
- Easy deployment.
- Simpler debugging for small applications.
- Less infrastructure complexity.
Disadvantages:
- Large codebase can become difficult to maintain.
- Scaling individual features independently is difficult.
- A deployment can affect the entire application.
9. Microservices Architecture
Microservices architecture divides an application into smaller, independently deployable services.
Advantages:
- Independent deployment.
- Independent scaling.
- Clear service responsibilities.
- Different technologies can be used where appropriate.
Disadvantages:
- More infrastructure complexity.
- Network communication failures.
- Distributed data consistency challenges.
- More complex monitoring and debugging.
10. Vertical and Horizontal Scaling
10.1 Vertical Scaling
Vertical scaling means increasing the resources of an existing server.
Example:
- Increase RAM from 8 GB to 32 GB.
- Increase CPU capacity.
- Use faster storage.
10.2 Horizontal Scaling
Horizontal scaling means adding more servers or application instances.
Load Balancer
|
+--------+--------+
| | |
v v v
Server 1 Server 2 Server 3
Horizontal scaling is commonly used for applications with increasing traffic.
| Vertical Scaling | Horizontal Scaling |
|---|---|
| Increase server capacity | Add more servers |
| Limited by machine capacity | Can expand across machines |
| Often simpler initially | Requires traffic distribution |
11. CAP Theorem
CAP theorem describes a trade-off in distributed data systems between three properties.
- Consistency: Reads return the latest successfully committed value according to the system's consistency guarantees.
- Availability: Every request to a non-failing node receives a response, even if it may not contain the latest data.
- Partition Tolerance: The system continues operating despite communication failures between parts of the distributed system.
When a network partition occurs, a distributed system must make trade-offs between consistency and availability.
12. Database Design
12.1 Relational Database
Relational databases store structured data in tables with defined relationships.
Examples: SQL Server, PostgreSQL, MySQL.
12.2 NoSQL Database
NoSQL databases support data models such as documents, key-value pairs, wide-column records, and graphs.
Examples:
- MongoDB – Document database.
- Redis – Key-value data store.
- Cassandra – Wide-column database.
12.3 Database Indexing
An index helps the database locate records more efficiently.
CREATE INDEX IX_Products_Name
ON Products(Name);
Indexes can improve read performance, but they also consume storage and add overhead to insert, update, and delete operations.
12.4 Database Replication
Replication copies data from one database server to another.
It can improve read scalability and support availability or disaster recovery, depending on the configuration.
12.5 Database Sharding
Sharding divides data across multiple database servers.
Example: Customers can be distributed across database partitions using a customer identifier or another shard key.
13. Caching Strategies
13.1 Cache-Aside
The application checks the cache first. If data is missing, it reads from the database and stores the result in the cache.
Application
|
v
Check Cache
|
+----+----+
| |
Hit Miss
| |
v v
Return Data Database
|
v
Update Cache
13.2 Write-Through
The application writes data to the cache and the underlying database as part of the write operation, according to the cache implementation.
13.3 Write-Behind
The application writes to the cache first, and the cache system updates the database asynchronously.
This requires careful handling of failures and data durability.
14. Synchronous vs Asynchronous Communication
Synchronous Communication
The caller waits for the called service to respond.
Example: An Order Service calls a Payment API and waits for the result.
Asynchronous Communication
The caller sends a message or event and continues without waiting for the consumer to finish processing it.
Example: An Order Service publishes an order event to RabbitMQ. A Notification Service processes it later.
15. Important Distributed System Concepts
- Timeout: Limits how long a request waits for a response.
- Retry: Attempts an operation again after a transient failure.
- Circuit Breaker: Temporarily stops calls to a failing dependency.
- Rate Limiting: Restricts how many requests a client can make.
- Idempotency: Repeating an operation does not create unintended additional effects.
- Dead Letter Queue: Stores messages that cannot be processed successfully.
- Eventual Consistency: Data across services becomes consistent over time.
- Service Discovery: Helps services locate one another.
- Distributed Tracing: Tracks a request across multiple services.
16. Security in System Design
- Use HTTPS/TLS for communication.
- Use OAuth 2.0 or OpenID Connect where appropriate.
- Validate and sanitize untrusted input.
- Apply role-based access control.
- Store secrets in a secure secret-management service.
- Encrypt sensitive data at rest where required.
- Apply rate limiting and abuse protection.
- Maintain audit logs.
- Apply least-privilege permissions.
17. Monitoring and Logging
Monitoring helps identify performance issues, failures, and resource usage.
Important metrics include:
- CPU utilization.
- Memory usage.
- Request rate.
- Response time.
- Error rate.
- Database query duration.
- Queue depth.
- Service availability.
Common tools include Azure Monitor, Application Insights, Prometheus, Grafana, and OpenTelemetry-compatible platforms.
18. Real-World Example: Designing an E-Commerce System
Assume we need to design an e-commerce application supporting a large number of customers.
Major Components
- Customer Service.
- Product Service.
- Cart Service.
- Order Service.
- Payment Service.
- Inventory Service.
- Notification Service.
Architecture
Order Placement Flow
- Customer selects products.
- Customer adds products to the cart.
- Customer submits an order.
- Order Service validates the request.
- Order Service creates a pending order.
- An order event is published to RabbitMQ.
- Payment Service processes payment.
- Inventory Service coordinates stock reservation or adjustment.
- Order status is updated based on the workflow result.
- Notification Service sends an order update.
Important: Payment, inventory, and order updates require carefully designed failure handling. A real system may use a Saga pattern, idempotency, and a transactional outbox rather than assuming every operation succeeds.
19. System Design in .NET
A typical modern .NET technology stack could look like this:
| Requirement | Technology |
|---|---|
| Backend API | ASP.NET Core Web API |
| Frontend | React / Angular |
| Database | SQL Server / PostgreSQL |
| Caching | Redis |
| Messaging | RabbitMQ / Azure Service Bus |
| API Gateway | YARP |
| Containerization | Docker |
| Orchestration | Kubernetes / AKS |
| Monitoring | Application Insights / OpenTelemetry |
| Cloud | Microsoft Azure / AWS |
20. How to Approach a System Design Interview
- Understand the problem: Clarify what the system should do.
- Identify requirements: Separate functional and non-functional requirements.
- Estimate scale: Understand users, requests, storage, and traffic patterns.
- Define APIs: Identify important endpoints and operations.
- Design data models: Identify entities, relationships, and database choices.
- Draw HLD: Show clients, gateways, services, databases, caches, and queues.
- Explain communication: Identify synchronous and asynchronous interactions.
- Address scaling: Explain load balancing, caching, replication, and sharding where appropriate.
- Address failures: Discuss retries, timeouts, circuit breakers, and recovery.
- Address security: Explain authentication, authorization, and data protection.
- Discuss trade-offs: Explain why you selected each technology and approach.
21. Common System Design Interview Questions
- What is system design?
- What is the difference between HLD and LLD?
- What is monolithic architecture?
- What is microservices architecture?
- When should we choose monolithic architecture over microservices?
- What is horizontal scaling?
- What is vertical scaling?
- What is a load balancer?
- What is an API Gateway?
- What is caching?
- What is Redis?
- What is database sharding?
- What is database replication?
- What is the CAP theorem?
- What is eventual consistency?
- What is a message queue?
- What is the difference between RabbitMQ and Kafka?
- What is a circuit breaker?
- What is idempotency?
- What is the Saga pattern?
- What is the transactional outbox pattern?
- How do you design a highly available application?
- How do you handle millions of API requests?
- How do you prevent database bottlenecks?
- How do you monitor a microservices application?
22. Popular System Design Problems to Practise
- Design an e-commerce application.
- Design an online shopping cart.
- Design a URL shortening service.
- Design a food delivery application.
- Design a taxi booking application.
- Design a notification service.
- Design a chat application.
- Design a video streaming platform.
- Design an online payment system.
- Design an inventory management system.
23. Important Points to Remember
- System design is about making architectural decisions, not just writing code.
- Always identify requirements before choosing technologies.
- Do not introduce microservices without a real need.
- Choose databases based on data and access patterns.
- Use caching for suitable frequently accessed data.
- Use asynchronous messaging for suitable background workflows.
- Design for failures, not just successful requests.
- Security must be considered from the beginning.
- Measure performance instead of making assumptions.
- Every architectural decision involves trade-offs.
24. Final Summary
System Design is the foundation of building large-scale software applications.
It combines application architecture, databases, APIs, caching, messaging, security, scalability, reliability, and monitoring.
For a .NET developer, a good starting point is to understand ASP.NET Core Web API, SQL Server, Redis, RabbitMQ, API Gateway, Docker, and cloud deployment.
Once these concepts are clear, practise designing real-world applications such as e-commerce, taxi booking, and food delivery systems.
| SAML - Security Assertion Markup Language :👈 | 👉:Terms Of Use/Disclaimer |
Comments and Discussion