Skip to content

.tip

· one of the small things

Prefix every public id with its type

A bare 01JCZ8QK in a log line or a bug report tells you nothing about what it points at, and a customer id pasted into an invoice field comes back as a 404 instead of a complaint about the field. Give every id you hand out a short type prefix and keep the rest opaque.

{ "id": "inv_01JCZ8QK", "customer": "cus_01JAB4RT", "amount": 4990 }

Check the prefix while you validate the request, so the wrong id is a 400 that names the field. The prefix belongs to the API, not the column: store the UUID and add it at the edge, or store the whole string as text.

api-designschema-design