Senior · Design · API design

Design a timestamp-plus-ID continuation with a signed token and an indexed backing store. Define lexicographic comparison, tenant binding and expiry. Separate the bounded returned page from database work and explain which consistency guarantees remain unprovided.

Think through your answer before opening the explanation.

Coding interviews

Reveal answer and reasoning

A composite timestamp-and-ID token should use lexicographic comparison in exactly the same directions as the result order. Encode and authenticate the token with query and tenant context, then validate size and expiry before using it. An indexed backing store is a separate implementation choice whose plan and consistency behavior need real verification.

For n source rows and m matching rows, filtering examines O(n) values and ordered-prefix evaluation buffers O(m) candidates. A full-sort baseline costs O(m log m), while .NET LINQ can optimize Take with partial selection; exact comparison behavior is implementation-dependent. An indexed ordered data source has another cost model. The small result page does not establish bounded total memory or an index seek.

Nonunique ordering keys can skip or repeat rows across pages unless a unique secondary key becomes part of the token. Concurrent inserts and deletes also require an explicit consistency policy. Local arrays provide no snapshot token, authorization boundary or tamper-resistant continuation encoding.

The solution is rigorous only when its unique-key, stable-key and page-size assumptions are visible. The tested code demonstrates deterministic continuation over an owned in-memory source and rejects an oversized request before enumeration. It deliberately does not demonstrate signed tokens, server authorization, index seeks or a durable snapshot. A senior explanation separates response bounds from total query work and describes what concurrent writes do to the cursor contract.

The related multi-file project adds composite ordering and explicit uniqueness checks as independent exercises, rather than quietly granting those properties to this smaller function.

What a strong answer covers

  • A composite timestamp-and-ID token should use lexicographic comparison in exactly the same directions as the result order.
  • For n source rows and m matching rows, filtering examines O(n) values and ordered-prefix evaluation buffers O(m) candidates.
  • Nonunique ordering keys can skip or repeat rows across pages unless a unique secondary key becomes part of the token.

Common pitfall

Nonunique ordering keys can skip or repeat rows across pages unless a unique secondary key becomes part of the token. Concurrent inserts and deletes also require an explicit consistency policy. Local arrays provide no snapshot token, authorization boundary or tamper-resistant continuation encoding.

Follow-up questions

  1. Insert a new row below and above the first continuation, then predict the next page. Hint: strict greater-than excludes earlier keys; that behavior is not the same as a frozen snapshot. Test the final empty page without indexing its last element.
  2. Which data must a continuation token bind when rows belong to different tenants?

Self-review

Choose what to revisit. These marks are your own assessment and are separate from lesson completion.

Primary references

Open lesson and code ↗

← All interview questions