An orders table is partitioned by customer id. A support tool now needs to find all orders with status 'late'. Compare a local index with a global index for this query and for the write path.
Sketch your own answer first, then compare it with the one below.
A strong answer
With a local index, each partition indexes its own orders by status. A write touches one partition, updating the row and its index entry together, so it stays cheap and consistent. The support query, though, must ask every partition and merge the answers. Latency is set by the slowest one, and the query's cost grows with the partition count. If each partition has a 1 percent chance of being slow, a query over 32 of them is slow about 28 percent of the time.
With a global index, partitioned by status, the query goes to the one index partition that holds 'late'. It is fast. But every status change now writes to two places, the order's partition and the index partition. Doing that atomically needs a distributed transaction, so most systems update the index asynchronously, and the query can briefly miss a change. DynamoDB's global secondary indexes behave this way. There is another catch: 'late' is a rare, hot value that all queries hit, so its index partition can become the bottleneck.
For a support tool queried a few times a minute, the local index is fine, and the fan-out is acceptable. If it was a customer-facing page hit thousands of times a second, I would use a global index, accept slightly stale results, and consider a separate table that holds only late orders.
Sources
- Martin Kleppmann (2017). Designing Data-Intensive Applications.
- Amazon Web Services (2024). Using global secondary indexes in DynamoDB.