Module 16: System Design Case Studies
Apply everything you’ve learned to real-world database design challenges. Each case study covers requirements, schema design, queries, scaling, and trade-offs.Estimated Time: 10-12 hours
Format: 6 comprehensive case studies
Interview Use: Practice for 45-60 min design rounds
Skill Level: Senior/Staff
Format: 6 comprehensive case studies
Interview Use: Practice for 45-60 min design rounds
Skill Level: Senior/Staff
Case Study 1: E-Commerce Platform
Requirements
- Product catalog with categories and attributes
- User accounts with addresses
- Shopping cart and checkout
- Order management with status tracking
- Inventory management with stock levels
- Review and rating system
Schema Design
Key Queries
Scaling Strategy
Case Study 2: Real-Time Analytics
Requirements
- Ingest millions of events per day
- Sub-second dashboard queries
- Time-series aggregations (hourly, daily, weekly)
- Retention: raw data 30 days, aggregates forever
Schema Design
Ingestion Pattern
Query Patterns
Data Lifecycle
Case Study 3: Social Media Feed
Requirements
- Users follow other users
- Home feed shows posts from followed users
- Support for 100M users, 10M DAU
- Feed must be < 100ms
Schema Design
Fan-Out Strategy
Feed Query (Hybrid)
Case Study 4: Multi-Tenant SaaS
Requirements
- Thousands of tenants (companies)
- Complete data isolation
- Some tenants are very large (1M+ rows)
- Compliance requirements (GDPR)
Schema Design (Shared with RLS)
Connection Management
Tenant Isolation Testing
Case Study 5: Event Sourcing System
Requirements
- All state changes stored as events (audit trail)
- Ability to rebuild state at any point in time
- Support for projections (read models)
- Event replay for debugging
Schema Design
Event Replay
Subscription Processing
Case Study 6: Global Application
Requirements
- Users in US, EU, Asia
- Data residency (EU data stays in EU)
- Low latency reads globally
- Strong consistency for writes
Architecture
Implementation
How to Use These Case Studies in Interviews
System design interviews for database engineering roles typically follow a 45-60 minute format. Here’s how to leverage these case studies for maximum interview success:Interview Structure and Timing
Phase 1: Requirements Clarification (5-10 minutes)- Ask about scale: How many users? Queries per second? Data volume?
- Identify read vs write ratio (often 90:10 or higher)
- Clarify consistency requirements: Strong vs eventual consistency?
- Understand geographic distribution and latency requirements
- Confirm data retention and compliance needs
- Start with a simple single-server design
- Identify the main entities and their relationships
- Draw a basic ER diagram or schema outline
- Explain your normalization choices
- Discuss primary access patterns and query shapes
- Schema Design: Walk through 2-3 core tables in detail
- Show primary keys, foreign keys, indexes
- Explain constraint choices
- Justify data types and column sizes
- Query Patterns: Write 2-3 critical queries
- Show how indexes support these queries
- Discuss query plan expectations
- Mention potential optimization techniques
- Scaling Bottlenecks: Identify the first scaling constraint
- Connection limits? I/O? CPU?
- Propose specific solutions (not just “add caching”)
- Progression from single server to scaled architecture
- Read scaling: Replicas, caching layers, CDN
- Write scaling: Partitioning, sharding strategies
- Handle trade-offs explicitly:
- “If we denormalize here, we gain X but lose Y”
- “Caching improves reads but introduces consistency challenges”
- Discuss monitoring and observability needs
- Mention backup and disaster recovery
- Consider operational complexity
- Address interviewer’s specific concerns
What Interviewers Look For
✅ Strong Signals:- Clear, structured thinking with explicit phases
- Asking clarifying questions before jumping to solutions
- Justifying design decisions with concrete trade-offs
- Concrete SQL examples, not just hand-waving
- Understanding when to denormalize and why
- Awareness of operational concerns (monitoring, backups)
- Scaling incrementally (not over-engineering initially)
- Immediately jumping to complex distributed systems
- Generic answers (“we’ll use microservices” without specifics)
- Not considering query patterns when designing schema
- Ignoring constraints and data integrity
- Proposing technologies without understanding their trade-offs
- Unable to write actual SQL queries
- No discussion of indexes or query optimization
Practice Strategies
1. Time Yourself: Set a 45-minute timer and work through a full case study 2. Write Actual SQL: Don’t just describe—write CREATE TABLE statements 3. Draw Diagrams: Practice drawing ER diagrams and architecture diagrams quickly 4. Explain Out Loud: Verbalize your thinking process as if explaining to an interviewer 5. Compare Your Solution: After completing, review the provided solution and note differences 6. Focus on Trade-offs: For every design choice, practice stating the pros and consCommon Interview Questions to Prepare
- “How would you handle hot partition problems in sharding?”
- “What’s your strategy for zero-downtime migrations?”
- “How do you ensure data consistency across microservices?”
- “Explain your approach to managing database schema changes in production.”
- “How would you optimize this query?” (given EXPLAIN output)
- “What monitoring metrics would you track for this system?”
Case Study to Interview Mapping
- E-Commerce: Tests inventory management, transactions, and consistency
- Analytics Platform: Tests time-series optimization and aggregation strategies
- Social Feed: Tests fan-out approaches and caching patterns
- Multi-Tenant SaaS: Tests isolation strategies and connection management
- Event Sourcing: Tests immutable data patterns and projections
- Global Application: Tests geo-distribution and data residency
Design Template: Build Your Own Case Study
Use this template to practice system design for any application domain:1. Requirements Analysis
Functional Requirements:- List 5-7 core features the system must support
- Identify the main entities and their relationships
- Define critical user workflows (e.g., checkout flow, post creation)
- Scale: How many users? Requests/second? Data volume?
- Read:Write Ratio: Typically 90:10, 95:5, or 50:50?
- Latency: P95/P99 targets (e.g., less than 100ms for reads, less than 500ms for writes)
- Consistency: Strong, eventual, or per-operation?
- Availability: Target uptime (e.g., 99.9%, 99.99%)?
2. Data Model Design
Core Entities Template:- All tables have explicit primary keys
- Foreign keys defined with appropriate ON DELETE behavior
- Unique constraints on natural keys (email, username, etc.)
- Check constraints for data validation
- Appropriate indexes for query patterns (list them explicitly)
- Consider partitioning strategy if time-series or very large tables
- JSONB columns only where schema flexibility is truly needed
3. Access Patterns and Queries
Identify Top 5 Queries by Frequency:- [Query description] - Expected QPS: ___
- [Query description] - Expected QPS: ___
- [Query description] - Expected QPS: ___
- [Query description] - Expected QPS: ___
- [Query description] - Expected QPS: ___
- Transactional writes (e.g., orders, payments)
- Bulk imports (e.g., data ingestion)
- Background jobs (e.g., aggregation, cleanup)
4. Indexing Strategy
5. Scaling Plan
Phase 1: Single Server (0-10K users)- Single PostgreSQL instance
- Application handles connection pooling
- Basic monitoring and backups
- Add 2-3 read replicas
- Implement read/write splitting in application
- Add Redis for session and hot data caching
- CDN for static assets
- Vertical scaling of primary (larger instance)
- Implement connection pooling (PgBouncer)
- Consider partitioning large tables by date/hash
- Asynchronous processing for non-critical writes
- Sharding strategy: [by user_id, by geographic region, etc.]
- Cross-shard query handling approach
- Multi-region deployment with data residency
- Event-driven architecture for eventual consistency
6. Trade-offs and Considerations
Consistency vs Performance:- Where can you use eventual consistency?
- Which operations require strong consistency?
- How do you handle consistency across shards?
- Which tables/columns will you denormalize? Why?
- What’s your strategy for keeping denormalized data in sync?
- Is sharding premature optimization for your scale?
- Can simpler solutions (caching, indexing) solve the problem?
7. Operational Considerations
Monitoring:- Key metrics to track (latency, throughput, error rate, saturation)
- Query performance tracking (pg_stat_statements)
- Replication lag monitoring
- Connection pool utilization
- Backup strategy and RPO (Recovery Point Objective)
- Restore and RTO (Recovery Time Objective)
- WAL archiving and PITR (Point-in-Time Recovery)
- How will you handle schema migrations with zero downtime?
- Versioning strategy for breaking changes
Self-Evaluation Rubric
Use this rubric to assess your case study solutions and identify areas for improvement:Requirements Understanding (Score: /10)
Excellent (9-10):- Asked clarifying questions about scale, consistency, and latency requirements
- Identified all implicit requirements (e.g., multi-tenancy, geographic distribution)
- Made reasonable assumptions where information was missing
- Documented assumptions explicitly
- Asked some clarifying questions
- Covered most critical requirements
- Made some assumptions but didn’t document all
- Jumped directly to solution without clarifying requirements
- Missed critical non-functional requirements
- Made unrealistic assumptions
Schema Design (Score: /20)
Excellent (17-20):- All entities properly normalized (or intentionally denormalized with justification)
- Appropriate data types and constraints
- Foreign keys with correct ON DELETE behavior
- Indexes match query patterns precisely
- Considered partitioning where appropriate
- JSONB used judiciously
- Mostly normalized schema
- Some indexes missing or unnecessary indexes included
- Minor data type issues
- Constraints mostly appropriate
- Normalization violations without justification
- Missing foreign keys or constraints
- No indexes or all indexes wrong
- Inappropriate use of JSONB for structured data
- Missing primary keys
Query Design (Score: /15)
Excellent (13-15):- All queries are efficient and use indexes
- Proper use of JOINs, CTEs, and window functions
- Transactions used appropriately for consistency
- Handles edge cases (NULL values, empty results)
- Queries are functional but not optimally efficient
- Some missed opportunities for index usage
- Minor correctness issues
- Queries don’t use available indexes
- N+1 query patterns
- Missing WHERE clauses or overly broad queries
- Incorrect JOIN types or conditions
Scaling Strategy (Score: /20)
Excellent (17-20):- Clear progression from simple to complex
- Specific solutions for read and write scaling
- Justified when to introduce each component
- Considered operational complexity
- Addressed specific bottlenecks (connection limits, I/O, CPU)
- Reasonable scaling approach
- Some components mentioned without detail
- Missing specific thresholds for scaling triggers
- Generic “use microservices” without specifics
- Over-engineered from the start
- No consideration of bottlenecks
- Proposed solutions don’t match requirements
Trade-off Analysis (Score: /15)
Excellent (13-15):- Every major decision includes explicit trade-offs
- Quantified trade-offs where possible (e.g., “10% write overhead for 50% read improvement”)
- Considered alternative approaches
- Addressed operational implications
- Some trade-offs discussed
- Mostly qualitative analysis
- Missing some alternative approaches
- No trade-off discussion
- Claims solutions are “best” without justification
- Doesn’t consider downsides
Operational Awareness (Score: /10)
Excellent (9-10):- Detailed monitoring plan
- Backup and disaster recovery strategy
- Schema migration approach
- Considered operational complexity and team skills
- Mentioned monitoring and backups
- Missing some operational details
- No discussion of operations
- Proposes complex system without considering maintenance
Communication Clarity (Score: /10)
Excellent (9-10):- Clear, structured presentation
- Used diagrams effectively
- Explained rationale for decisions
- Easy to follow progression
- Mostly clear
- Some organization issues
- Could use more diagrams
- Difficult to follow
- Jumps around randomly
- No visual aids
Total Score: ___/100
90-100: Excellent - Ready for staff+ interviews 75-89: Good - Solid senior-level understanding 60-74: Fair - Has foundational knowledge but needs more practice Below 60: Needs Improvement - Review fundamentals and practice moreAction Items Based on Your Score
If you scored below 70:- Review the fundamentals in earlier modules (especially Database Design and Performance)
- Practice writing actual SQL, not just describing solutions
- Focus on one case study at a time and compare your solution to the provided one
- Deepdive into areas where you scored lowest
- Practice explaining trade-offs out loud
- Time yourself on case studies to improve pacing
- Write more detailed schemas and queries
- Practice more complex variations
- Focus on communication and presentation
- Review edge cases and failure scenarios
- Consider mentoring others to solidify your knowledge
Capstone Project: Build a Complete Database-Backed System
Put everything together by building a production-ready system from scratch:Project Overview
Design, implement, and document a complete database-backed application that demonstrates mastery of all course concepts. Duration: 2-4 weeksOutcome: Portfolio piece suitable for interviews
Format: Working application + comprehensive documentation
Project Requirements
Choose ONE of these domains:- Multi-Tenant SaaS Analytics Platform: Track events, generate reports, support multiple customers
- Real-Time Collaborative Tool: Like Google Docs or Figma, with conflict resolution
- E-Learning Platform: Courses, enrollments, progress tracking, assessments
- Inventory Management System: Multi-warehouse, real-time stock, order fulfillment
- Social Media Feed Engine: Posts, follows, timeline generation, notifications
- OR propose your own (must be approved based on complexity)
Implementation Checklist
Phase 1: Design and Planning (Week 1)
- Write a requirements document (functional and non-functional)
- Create detailed ER diagram with cardinality
- Design complete schema with all constraints
- Identify top 10 query patterns
- Plan indexing strategy
- Document normalization decisions and intentional denormalizations
Phase 2: Core Implementation (Week 1-2)
- Set up PostgreSQL database (local or cloud)
- Implement complete schema with migrations
- Seed database with realistic test data (use faker libraries)
- Implement all core queries with EXPLAIN ANALYZE results
- Add appropriate indexes and verify performance
- Write SQL-level tests for critical queries
Phase 3: Application Layer (Week 2-3)
- Build simple API or web app that uses the database
- Implement connection pooling (PgBouncer or application-level)
- Add basic authentication and authorization
- Implement at least one complex transaction (e.g., checkout, enrollment)
- Handle concurrent access scenarios
- Add error handling and validation
Phase 4: Performance and Scaling (Week 3)
- Set up pg_stat_statements for query monitoring
- Profile top queries and optimize
- Implement caching layer (Redis or similar) for hot data
- Add read replica (if using cloud provider)
- Load test with realistic traffic patterns
- Document performance baselines
Phase 5: Production Readiness (Week 4)
- Set up automated backups
- Implement monitoring dashboards (Grafana or similar)
- Add alerts for critical metrics
- Create runbook for common operational tasks
- Implement graceful degradation for failures
- Document disaster recovery procedures
Deliverables
1. Code Repository (GitHub/GitLab)- Schema migrations (versioned)
- Seed data scripts
- Application code
- Test suite
- README with setup instructions
- Requirements and assumptions
- ER diagrams and schema design
- Query patterns and access patterns
- Indexing strategy with justifications
- Scaling plan (current + future)
- Trade-off analysis
- Query performance benchmarks (EXPLAIN ANALYZE outputs)
- Load testing results (throughput, latency percentiles)
- Bottleneck analysis
- Optimization decisions and their impact
- Monitoring setup and key metrics
- Backup and restore procedures
- Common troubleshooting scenarios
- Schema migration workflow
- Disaster recovery plan
Evaluation Criteria
Technical Depth (40%)- Schema design quality and normalization
- Query optimization and index usage
- Transaction handling and concurrency
- Performance under load
- Monitoring and observability
- Error handling and resilience
- Backup and recovery capability
- Security considerations
- Clear architecture and design decisions
- Trade-off analysis
- Operational procedures
- Code comments and README
- All phases completed
- Realistic data and scenarios
- Working end-to-end
Success Examples
Excellent Projects Include:- Thoughtful denormalization with documented trade-offs
- Creative use of PostgreSQL features (JSONB, CTEs, window functions)
- Real performance optimization with before/after metrics
- Production-quality error handling and logging
- Comprehensive monitoring setup
- Using MongoDB or MySQL when PostgreSQL was required
- No indexes or all wrong indexes
- Hand-waving instead of actual implementation
- No performance testing
- Generic solutions without domain-specific optimization
Bonus Challenges (Optional)
For extra depth, consider adding:- Multi-region deployment with data residency
- Sharding implementation for a specific table
- Custom PostgreSQL extension
- Advanced full-text search with ranking
- Event sourcing pattern for audit trail
- GraphQL API with optimized data loader
- Real-time subscriptions using PostgreSQL LISTEN/NOTIFY
Getting Help
- Post questions in course Discord
- Schedule 1:1 code reviews (if available)
- Share your design doc for feedback before full implementation
- Present your project to peers for practice
Summary
You’ve now seen how to apply database design principles to real-world systems:E-Commerce
Inventory, orders, flexible attributes
Analytics
Time-series, pre-aggregation, partitioning
Social Feed
Fan-out, hybrid approach, caching
Multi-Tenant
RLS, isolation, connection management
Event Sourcing
Append-only, projections, replay
Global
Geo-routing, data residency, federation
Course Completion 🎉
Congratulations! You’ve completed the Database Engineering Mastery course.
- Senior/Staff engineering interviews
- PostgreSQL open-source contributions
- Production database architecture and operations