🏛️ System Design Interview Questions

SOLID principles, design patterns, microservices architecture, and API design best practices

15-Minute Design Patterns Cheatsheet

Quick reference for last-minute interview preparation

🏛️ SOLID Principles

S - Single Responsibility: One reason to change
O - Open/Closed: Open for extension, closed for modification
L - Liskov Substitution: Subtypes replaceable
I - Interface Segregation: Small, specific interfaces
D - Dependency Inversion: Depend on abstractions

🔨 Creational Patterns

Singleton: One instance, global access point
Factory: Create objects without exposing logic
Abstract Factory: Families of related objects
Builder: Complex objects step by step
Prototype: Clone existing objects

🏗️ Structural Patterns

Adapter: Convert interface to another
Decorator: Add behavior dynamically
Facade: Simplified interface to complex system
Proxy: Placeholder for another object
Composite: Tree structures, uniform treatment

🔄 Behavioral Patterns

Observer: Pub/sub, event handling
Strategy: Interchangeable algorithms
Command: Encapsulate requests as objects
State: Behavior changes with state
Template Method: Algorithm skeleton, steps vary

🌐 Architecture Patterns

MVC: Model-View-Controller separation
Microservices: Independent, deployable services
Event-Driven: Loosely coupled via events
CQRS: Separate read/write models
Hexagonal: Ports and adapters

🔌 API Design

REST: Resources, HTTP verbs, stateless
GraphQL: Query language, single endpoint
gRPC: Binary protocol, streaming
Versioning: URL, header, or query param
Pagination: Offset, cursor, keyset

🔷 Microservices Patterns

API Gateway: Single entry point
Service Discovery: Dynamic endpoints
Circuit Breaker: Fail fast, recover
Saga: Distributed transactions
Event Sourcing: State from events
Sidecar: Auxiliary containers

⚠️ Common Interview Questions

• When would you use Factory vs Builder?
• How does Dependency Injection help testing?
• Monolith vs Microservices trade-offs?
• How to handle distributed transactions?
• Design a URL shortener / rate limiter
• How to ensure idempotency in APIs?

SOLID Principles

Explain SOLID principles with real-world examples

Hard

SOLID is an acronym for five design principles that make software more maintainable, scalable, and flexible.

1. Single Responsibility Principle (SRP)

A class should have only one reason to change - it should have only one job or responsibility.

2. Open/Closed Principle (OCP)

Software entities should be open for extension but closed for modification.

3. Liskov Substitution Principle (LSP)

Objects of a superclass should be replaceable with objects of a subclass without breaking the application.

4. Interface Segregation Principle (ISP)

Clients should not be forced to depend on interfaces they don't use.

5. Dependency Inversion Principle (DIP)

High-level modules should not depend on low-level modules. Both should depend on abstractions.

Microservices Architecture

Explain common microservices design patterns

Hard

Microservices architecture requires specific patterns to handle distributed systems challenges.

1. API Gateway Pattern

Single entry point for all clients. Routes requests to appropriate microservices.

TypeScript

2. Circuit Breaker Pattern

Prevents cascading failures by stopping requests to failing services.

TypeScript

3. Saga Pattern (Distributed Transactions)

Manages data consistency across microservices through a sequence of local transactions.

TypeScript

4. Service Discovery Pattern

Automatically detect network locations of service instances.

TypeScript

5. CQRS Pattern (Command Query Responsibility Segregation)

Separate read and write operations for better scalability and performance.

TypeScript

Design Patterns (GoF)

Explain common design patterns (Singleton, Factory, Observer, Strategy)

Medium

1. Singleton Pattern

Ensures a class has only one instance and provides a global point of access.

2. Factory Pattern

Creates objects without specifying the exact class to create.

3. Observer Pattern

Defines a one-to-many dependency so that when one object changes state, all dependents are notified.

4. Strategy Pattern

Defines a family of algorithms, encapsulates each one, and makes them interchangeable.

API Design

Explain REST API design best practices and common patterns

Medium

RESTful API design follows specific conventions and best practices for building maintainable, scalable APIs.

1. Resource Naming Conventions

JavaScript

2. HTTP Status Codes

JavaScript

3. Versioning Strategies

JavaScript

4. Pagination, Filtering, and Sorting

TypeScript

5. Error Handling Pattern

TypeScript

Explain the difference between Monolithic and Microservices architecture

Medium

Monolithic Architecture

All components of the application are tightly coupled and deployed as a single unit.

  • Pros:
    • Simple to develop and test initially
    • Easy to deploy (single deployment unit)
    • Better performance (no network calls between components)
    • Easier debugging and tracing
    • Simpler transaction management
  • Cons:
    • Difficult to scale specific features
    • Large codebase becomes hard to maintain
    • Slow deployment (must redeploy entire app)
    • Technology stack locked in
    • Single point of failure

Microservices Architecture

Application is decomposed into small, independent services that communicate over network.

  • Pros:
    • Independent scaling of services
    • Technology diversity (different tech stack per service)
    • Faster deployment (deploy only changed services)
    • Better fault isolation
    • Easier to understand smaller codebases
    • Team independence
  • Cons:
    • Increased complexity (distributed systems)
    • Network latency and failures
    • Difficult to test end-to-end
    • Data consistency challenges
    • More operational overhead (multiple deployments)
    • Debugging is harder
text

Explain Database Design Patterns and Normalization

Medium

Database Normalization Forms

Normalization organizes data to reduce redundancy and improve data integrity.

SQL

Common Database Design Patterns

SQL

Interview Tips for Design Patterns & Architecture