Agent Wranglers

Lists Recommended

Sort in a stable order

Sort every list in a documented, stable order, and let clients choose from a fixed set of sort keys.

How to do it

Default to a unique key, such as creation time plus ID, so equal values never swap between pages. Accept a parameter such as sort=-createdAt with an allow-list of fields. Add the ID as the last sort key to any sort the client picks.

How to check

Two identical list requests return items in the same order, and an unlisted sort field gets 400.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers api design playbook: https://agentwranglers.se/playbook/api-design/lists/sorting.