Choosing a Stable Order for Web Result Lists

A web result list needs a repeatable order before applying a page limit or cursor. Ties should be resolved by a meaningful stable field.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two equal timestamps
  2. Match interaction semantics
  3. Make ties predictable at a page boundary
  4. Separate deterministic sorting from snapshot consistency

Trace two equal timestamps

If two articles share a timestamp, ordering by timestamp plus ID can place them consistently. With a time-only order, different executions can place tied articles across the page boundary differently. See cursor boundaries.

Match interaction semantics

“Most recent” might mean publication time or update time. Document which timestamp provides the primary key and preserve that choice in sorting by key.[1][2]

Make ties predictable at a page boundary

Suppose several items share the same displayed timestamp. Ordering by timestamp alone can give different relative positions for tied rows. Add a durable unique key as a second criterion if repeatability matters. Use the same order when encoding a cursor. See query ordering with two fields.

Newest timestamp first
Rows A and B tie on timestamp
Choose ascending IDs as second order
A and B then occupy predictable positions in a static snapshot

Separate deterministic sorting from snapshot consistency

Live insertions, deletions or edits can still alter later pages. Choose and document the consistency users receive. Test tied rows on either side of a page boundary.

References

  1. IETF, RFC 9110: HTTP Semantics ↩
  2. WHATWG, HTML Living Standard: Forms ↩