System Design Flashcards

(20 cards)

1
Q

What are the key components of a system design interview?

A

Key components include gathering requirements, designing high-level architecture, choosing technologies, addressing scalability, and handling trade-offs. Example: For a URL shortener, define inputs (long URLs), outputs (short URLs), and scale (millions of users).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you design a scalable REST API?

A

Use a layered architecture: Load balancer → API servers (e.g., Node.js) → Database (e.g., PostgreSQL). Implement caching (Redis), rate limiting, and horizontal scaling. Example: Route requests via NGINX, cache responses, shard database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between horizontal and vertical scaling?

A

Horizontal scaling adds more servers (e.g., more API instances); vertical scaling increases a server’s resources (e.g., more CPU). Horizontal is preferred for distributed systems due to flexibility.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a load balancer, and how does it work?

A

A load balancer distributes traffic across servers to ensure availability. Example: NGINX routes requests to multiple Node.js instances using round-robin or least connections, improving throughput.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you design a database schema for a social media app?

A

Tables: Users (id, name), Posts (id, user_id, content), Comments (id, post_id, user_id). Use foreign keys for relationships, index user_id for fast queries. Normalize for consistency, denormalize for read-heavy loads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the CAP theorem, and how does it affect system design?

A

CAP theorem states a distributed system can only guarantee two of: Consistency, Availability, Partition Tolerance. Example: Choose high availability (MongoDB) for social apps or consistency (MySQL) for banking.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you handle high traffic in a system?

A

Use load balancers, caching (Redis), CDNs for static assets, and database sharding. Example: Cache user profiles in Redis to reduce database load, scale API servers horizontally.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is caching, and how is it implemented in a full-stack app?

A

Caching stores frequently accessed data for fast retrieval. Example: Use Redis to cache API responses in a Node.js backend, reducing database queries (O(1) lookup).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you design a rate limiter for an API?

A

Implement in-memory storage (Redis) to track requests per user/IP in a time window. Example: Allow 100 requests/hour per IP, reject excess with HTTP 429. Use sliding window for accuracy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is sharding, and when is it used?

A

Sharding splits a database into smaller, independent pieces (shards) based on a key (e.g., user_id). Used for large-scale data to improve performance. Example: Shard users by region.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you design a URL shortener service?

A

Components: API (POST /shorten, GET /:id), database (short_id, long_url), hash function (e.g., base62). Scale with sharding, caching redirects in Redis. Handle collisions with unique IDs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a CDN, and how does it improve performance?

A

A CDN (Content Delivery Network) caches static content (e.g., images, CSS) on edge servers near users. Example: Cloudflare serves React app assets, reducing latency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you ensure data consistency in a distributed system?

A

Use strong consistency (e.g., distributed locks, Paxos) for critical data or eventual consistency (e.g., DynamoDB) for high availability. Example: Bank transactions need strong consistency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between SQL and NoSQL in system design?

A

SQL (e.g., PostgreSQL) is structured, relational, best for complex queries; NoSQL (e.g., MongoDB) is flexible, scalable, ideal for unstructured data or high write loads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you design a notification system?

A

Components: Queue (Kafka) for events, workers to process notifications, database for user preferences. Use WebSockets for real-time or email/SMS APIs. Scale with partitioning.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is eventual consistency, and where is it used?

A

Eventual consistency means updates propagate over time, prioritizing availability. Used in NoSQL (e.g., Cassandra) for apps like social media where slight delays are acceptable.

17
Q

How do you handle database migrations in a production system?

A

Use tools like Flyway or Liquibase for versioned migrations. Apply changes incrementally, test in staging, and use backward-compatible schemas to avoid downtime.

18
Q

What is a microservices architecture, and what are its trade-offs?

A

Microservices split an app into small, independent services (e.g., user service, payment service). Pros: scalability, flexibility. Cons: complexity, inter-service communication overhead.

19
Q

How do you design a chat application?

A

Components: WebSocket servers for real-time messaging, database (MongoDB) for message history, Redis for user presence. Scale with sharded message storage and load-balanced servers.

20
Q

How do you optimize a system for low latency?

A

Use caching (Redis), CDNs, database indexing, and asynchronous processing (queues). Example: Cache API results, use in-memory DB for hot data, optimize queries with indexes.