Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Multi-Tenant Order-Statistics Index

Design a frequently updated tenant-aware index that answers kth-smallest record queries safely.

Problem statement

Design an index for a database table with frequent modifications and frequent kth-smallest queries. Augment a B+ tree with subtree-like counts so rank traversal can locate a record without scanning preceding rows.

Different tenants may see different filtered data, so unfiltered shared counts cannot answer every tenant's query. Compare tenant-isolated indexes with shared tenant-keyed structures and a hybrid model, including isolation, resource, and noisy-neighbor trade-offs.

For this exercise, assume 10,000 tenants, one billion logical rows, 200,000 writes and 100,000 rank queries per second, p99 query latency below 100 ms, read-after-write consistency within a tenant, and online split, merge, and repair.

What to build

  1. Insert, update, or delete a tenant-visible record and atomically maintain rank-count metadata.
  2. Return the kth-smallest record under one tenant's declared ordering and visibility filter, or an out-of-range result.
  3. Split, merge, rebuild, and reconcile index partitions without leaking data or corrupting counts.

At scale

  • Source-backed design: B+ tree navigation uses maintained child or subtree counts to locate records by rank.
  • Source-backed design pressure: tenant-specific visibility makes global unfiltered counts invalid and requires an isolation strategy.
  • Practice assumption: 10,000 tenants and one billion rows drive 200,000 writes and 100,000 rank queries per second.
  • Practice assumption: tenant reads require read-after-write consistency and p99 kth-query latency below 100 ms.