Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Courses/Distributed Architecture
Lesson 4 of 24

Data modelling for scale

Model data from access patterns, choose partition keys deliberately, and denormalise where reads demand it.

20 min read

Start from the queries

On one relational server you normalise and let the query planner join anything. At scale, joins across partitions are expensive or unavailable, so you design the schema around the queries you must answer fast. List the access patterns with their rates before drawing tables: get task by id (8 000 per second), list a user's open tasks newest first (3 000 per second), count tasks per project (50 per second). The top two or three patterns decide the keys; rare queries can go to a secondary index, a search engine or a warehouse.

Partition keys and sort keys

Wide-column and key-value stores (Cassandra, DynamoDB, Bigtable) organise data by a partition key, which decides the machine, and a sort or clustering key, which orders rows within the partition. A query that names one partition and a range of sort keys is a single, fast, sequential read. A query that does not name the partition must scan every node.

  • user_id as partition key plus created_at as sort key serves a user's timeline in one read
  • Keep partitions bounded: Cassandra guidance is roughly under 100 MB per partition
  • A DynamoDB partition serves about 3 000 reads and 1 000 writes per second; one hot key cannot exceed that

Denormalise deliberately

Storing the author's display name on every comment avoids a lookup on each of 50 comments per page, but now a name change must update many rows. That trade is worth it when reads outnumber writes by 100 to 1 and staleness of a few seconds is acceptable. Propagate the change asynchronously through an event stream, and record which copy is the source of truth so a reconciliation job can repair drift. If the copied field changes constantly, such as a live follower count, do not copy it: fetch it from a cache at read time.

Relational is still often right

A single PostgreSQL primary on modern hardware handles tens of thousands of transactions per second and several terabytes. If your data fits, keep it relational, use read replicas for read scale, and enjoy transactions and ad hoc queries. Reach for a partitioned store when you can name the limit you are hitting: write throughput, data size, or the need to be in several regions at once. Before that, cheaper steps often buy years: better indexes, archiving cold rows, moving analytics to a warehouse, and caching hot reads.

Key takeaways

  • List access patterns with their rates before choosing keys or a database
  • The partition key decides where data lives; queries that omit it hit every node
  • Denormalise for read-heavy paths and propagate changes asynchronously from a single source of truth
  • A single relational primary goes further than most people think; partition when you can name the limit

Sign in to track lessons and earn badges.

API gateways and service meshStorage engines: B-trees and LSM trees

Coming up

Course: 0/24 lessons · 0/10 challenges0%

Build it on the canvas, pass the review (70+) and mark it complete to count it toward the course badge.

  1. 3/10Design a Hotel Booking SystemPrevent double booking with transactional holds and sagas while keeping availability search fast.Medium
  2. 4/10Design an Inventory ServiceKeep stock counts exact under concurrent orders using conditional updates, reservations and idempotent events.
Medium
All 10 challenges →