SQL Practice Logo

SQLPractice Online

Database System Fundamentals: Real-World

Module: Database-Specific Features

Uber uses PostgreSQL MVCC for high-concurrency ride matching (50K writes/sec, zero blocking reads). Shopify uses MySQL InnoDB for e-commerce transactions (100K orders/min, ACID guarantees). Netflix uses multiple databases: PostgreSQL for billing (ACID), Cassandra for viewing history (scale). Understanding database fundamentals helps you choose the right system and configure it correctly. Wrong choice costs millions: Twitter migrated from MySQL to Manhattan (custom) after scaling issues. Stripe chose PostgreSQL over MySQL for better JSON support and extensibility.

Uber: MySQL to PostgreSQL Migration - MVCC for High Concurrency

Uber initially used MySQL for ride matching. Problem: 50K driver location updates/sec (writes) blocked user searches for rides (reads). MySQL InnoDB locking: writers acquire exclusive locks, blocking readers. User searches timed out (5+ seconds), bad experience. Revenue impact: $100K/hour in lost rides. Root cause: MySQL locking architecture can't handle high write concurrency with non-blocking reads.

Migrated ride matching service from MySQL to PostgreSQL. PostgreSQL MVCC allows writers and readers to work simultaneously without blocking. Writers create new row versions (driver location updates), readers see old versions (user searches). Zero blocking. User searches complete in <100ms even with 50K writes/sec. Migration process: (1) Setup PostgreSQL replica, (2) Dual-write to MySQL and PostgreSQL, (3) Verify data consistency, (4) Switch reads to PostgreSQL, (5) Switch writes to PostgreSQL, (6) Decommission MySQL. Total time: 6 months. Cost: $10M in engineering time. Benefit: Enabled 10x growth in rides without scaling issues.

-- Before: MySQL InnoDB with locking

-- Transaction 1: User searches for rides (reader)

BEGIN;

SELECT driver_id, latitude, longitude,

ST_Distance(location, ST_Point(40.7128, -74.0060)) as distance

FROM drivers

WHERE status = 'available'

AND ST_Distance(location, ST_Point(40.7128, -74.0060)) < 5000

ORDER BY distance

LIMIT 10;

-- Acquires shared locks on drivers table

-- Blocks Transaction 2 (writer)

-- Transaction 2: Driver location update (writer)

BEGIN;

UPDATE drivers

SET latitude = 40.7589,

longitude = -73.9851,

location = ST_Point(40.7589, -73.9851),

updated_at = NOW()

WHERE driver_id = 12345;

-- Waits for Transaction 1's shared lock to release

-- LOCK WAIT: 5 seconds

-- User search times out

COMMIT;

-- After: PostgreSQL with MVCC

-- Transaction 1: User searches for rides (reader)

BEGIN; -- Snapshot at xid=1000

SELECT driver_id, latitude, longitude,

ST_Distance(location, ST_Point(40.7128, -74.0060)) as distance

FROM drivers

WHERE status = 'available'

AND ST_Distance(location, ST_Point(40.7128, -74.0060)) < 5000

ORDER BY distance

LIMIT 10;

-- Sees snapshot at xid=1000

-- No locks acquired