Part 5 of 5 · 4 min read
Exercises
Easy
Easy 1: Define a secondary index in a partitioned system (15 minutes)
State why a secondary index needs its own partitioning decision, separate from the main table's partitioning.
Done when: the fact that a secondary index is built on a column other than the primary partitioning key, so its rows are not naturally grouped together, is correctly stated.
Hint
A secondary index is built on a column other than the primary partitioning key, so its matching rows are not naturally grouped on one partition.
Easy 2: Name the two secondary-indexing approaches (15 minutes)
Name the two approaches to partitioning a secondary index covered on this page.
Done when: document-partitioned (local) and term-partitioned (global) are both correctly named.
Hint
Document-partitioned (local) indexing and term-partitioned (global) indexing.
Easy 3: Define a scatter-gather query (15 minutes)
State what a scatter-gather query is.
Done when: a query sent to every partition, with results merged into one answer, is correctly described.
Hint
A query sent to every partition, with each partition's results combined into one final answer.
Medium
Medium 1: Identify which approach needs scatter-gather (25 minutes)
State which of the two secondary-indexing approaches requires a scatter-gather query to answer a lookup.
Done when: document-partitioned (local) indexing is correctly identified as requiring scatter-gather, since each partition only covers its own rows.
Hint
Document-partitioned (local) indexing, since each partition only knows about its own rows.
Medium 2: Choose an approach for a write-heavy workload (25 minutes)
A system writes rows at extremely high volume but rarely queries the secondary index. Recommend a secondary-indexing approach.
Done when: document-partitioned (local) indexing is recommended, correctly reasoning that its cheap, single-partition writes outweigh its more expensive reads here, given how rare reads on this index are.
Hint
Document-partitioned (local) indexing, since cheap writes matter far more here than occasional, more expensive reads.
Medium 3: Choose an approach for a read-heavy workload (30 minutes)
A system rarely writes new rows but frequently queries the secondary index for a specific value. Recommend a secondary-indexing approach.
Done when: term-partitioned (global) indexing is recommended, correctly reasoning that its targeted, cheap reads outweigh its more expensive writes here, given how rare writes are.
Hint
Term-partitioned (global) indexing, since cheap, targeted reads matter far more here than occasional, more expensive writes.
Hard
Hard 1: Explain why a global index write can touch two partitions (30 minutes)
Explain, step by step, why writing a single row with a term-partitioned secondary index can require updating two different partitions rather than one.
Done when: the explanation correctly describes that the row itself is written to its primary partition, while the term-partitioned index entry for that row's indexed value lives on whichever index partition covers that value, which may be a different partition entirely, requiring both to be updated.
Hint
The row is written to its own primary partition, while its term-partitioned index entry lives on a separate index partition determined by the indexed value, so both must be updated.
Hard 2: Evaluate scatter-gather's scaling behavior (35 minutes)
Explain why adding more partitions to a system using document-partitioned secondary indexes does not make scatter-gather queries on that index faster, and may make them slower.
Done when: the explanation correctly notes that a scatter-gather query must still contact every partition regardless of how many there are, so more partitions means more individual requests to issue and wait on, with total latency bounded by the slowest-responding partition.
Hint
A scatter-gather query must contact every partition no matter how many exist, so more partitions means more requests and a total latency bounded by the slowest one to respond.
Hard 3: Design a hybrid approach for a mixed workload (40 minutes)
A system has one secondary index queried constantly at high volume, and several other secondary indexes queried rarely. Propose how to apply document-partitioning and term-partitioning differently across these indexes, and justify the choice.
Done when: a reasonable proposal is given, such as term-partitioning the frequently queried index to keep its reads cheap, while document-partitioning the rarely queried indexes to keep their writes cheap, with the justification correctly connecting each index's own read-versus-write frequency to the approach chosen for it.
Hint
Term-partitioning the heavily queried index keeps its reads cheap, while document-partitioning the rarely queried indexes keeps their writes cheap, matching each index's own read-versus-write balance to the approach that favors it.