<aside>

This section is part of the 5-hour System Design course by Mukul Raina

SLIDE 96: Section Intro, Database Design

Section 8: Database Design

image.png

A ride-sharing platform does not have one database. It has several, each chosen for a specific data type and access pattern. User profiles live in PostgreSQL. Real-time driver positions live in Redis. Location history lives in a time-series database. Payment transactions live in their own PostgreSQL instance with ACID guarantees. The architectural question is not “which database should we use?” It is “which database should we use for each data type, and why?”

This section makes that decision for every data type in the system, defines schemas with concrete column names and indexes, and explains the sharding strategy that makes geographic partitioning work.

What We’ll Cover:

  1. Database-per-service pattern and why shared databases fail
  2. Technology selection per data type: PostgreSQL, Redis, time-series DB, Elasticsearch
  3. Schemas, indexes, and query patterns for users, trips, payments, and locations
  4. Geographic sharding: why ride-sharing shards by city, not by user
  5. Denormalization trade-offs and the full entity-relationship model

This section connects backward to Section 5 (Data Flow), where we defined which services own which data, and forward to Section 11 (Scaling), where we scale these databases across regions.

<aside>

Mukul Raina | youtube.com/@mukulraina | slides.mukulraina.com | LinkedIn

</aside>


SLIDE 97: Database-Per-Service Pattern

Each Service Owns Its Database

No service directly queries another service’s database. Trip Service owns trip records. Location Service owns positions. Payment Service owns transactions. If Matching Service needs trip data, it calls Trip Service’s API or consumes its Kafka events. It never runs SQL against Trip Service’s database.

image.png