KatInterview

Database Indexing and Scaling for High-Volume Profile Lookups

System DesignModel answer
MediumModel answerSystem Designdatabasesindexingcaching

Last updated

Design indexing, caching, and scaling strategies for a user profile database handling 10K QPS with regional skew.

Context

You're building the data layer for a global customer management platform. The system stores user profiles in a relational database with approximately 5 million records today, increasing by roughly 50,000 records monthly. The application serves two primary query patterns: direct profile retrieval using a user identifier and region code, and batch operations that fetch or count all users within a particular region.

Current Scale and Traffic

  • Data volume: 5 million user records, approximately 5 GB total size
  • Read load: 10,000 queries per second at peak (roughly 9,000 individual lookups and 1,000 regional queries)
  • Write load: 500 updates per second at peak, primarily to preference and compliance fields
  • Geographic distribution: Traffic and data are heavily skewed—65% North America, 25% Europe/Middle East/Africa, 10% Asia-Pacific
  • Performance target: 99th percentile latency under 10 milliseconds for individual profile lookups
  • Consistency: Updates must be visible to the updating user immediately (read-after-write consistency)

Schema Overview

The user profile table contains:

  • user_id: unique identifier (assume globally unique)
  • region: geographic region code (3 distinct values)
  • status: account status (active, suspended, closed, etc.)
  • entitlements, preferences, compliance: structured data fields
  • updated_at: last modification timestamp

Your Task

Design a comprehensive solution covering:

  1. Indexing decisions: Which columns should be indexed, in what order, and why? Consider both query patterns and how index selectivity affects performance.

  2. Partitioning evaluation: Should the table be partitioned? If so, by what key and at what scale? What are the trade-offs of partitioning early versus deferring it?

  3. Horizontal scaling approach: How would you scale reads and writes beyond a single database instance? Compare different replication and sharding strategies given the regional skew.

  4. Practical trade-offs: Discuss maintenance overhead, write amplification from indexes, cache consistency challenges, and how your design would evolve as data grows 10x.

Include specific schema definitions, configuration choices, and quantitative reasoning about when different optimizations become necessary.

Hints

Hint 1

Calculate whether the entire dataset and indexes fit in memory on a single modern database instance—this fundamentally changes your architecture choices.

Hint 2

For composite indexes, think about which query pattern benefits from each column ordering and what the cardinality of each column tells you about index effectiveness.

Hint 3

Regional skew matters differently for partitioned versus replicated architectures—consider how load distributes in each approach.