Mixed ISO 8601 timestamp formats cause unexpected sort order in DynamoDB queries
0 reputation · 14 Jun 2020, 22:04 UTC
Goal: store a timestamp attribute that supports correct chronological ordering for range queries and enables prefix‑based filters when used as a DynamoDB sort key.
Constraint: the attribute must be stored in a single canonical format because mixing UTC ISO 8601 strings, offset‑containing strings, or epoch numbers breaks lexicographic or numeric sort order and invalidates between/>= operations. Additionally, TTL requires a Number attribute in epoch seconds, and begins_with‑style queries only work on string sort keys.
Uncertainty: deciding whether to use a fixed‑format UTC ISO 8601 string (which preserves sort order and allows prefix queries) or an epoch number (which guarantees numeric order and satisfies TTL directly) while still meeting the application’s query patterns.
Which format gives reliable sort order and prefix query support?
How should TTL be handled if the primary timestamp is stored as an ISO string?
What are the trade‑offs of storing offsets in the timestamp string for regional display?