Custom prefixes for UUID primary keys?

I’m working with loosely coupled services and databases that rely on UUIDv4 as their primary keys. Ecto supports this very easily out of the box. No more auto-incrementing keys! One of the really nice advantages is that each UUID is unique throughout the entire system, no matter which table or database it is in. However, I’m wondering how we might implement something even better: how can we add a short prefix to each key to help humans identify each key without having to go on a wild goose-chase to determine its source. I’m thinking something like Stripe’s API, where each resource has an id like cus_ab134axcvasf or tok_hg212fasdf so it’s clear at a glance the resources being referred to are users or tokens respectively.

I feel like this might be pushing too much against the grain of what’s possible with PostGres. Has anyone implemented something like this? Any pointers?

Thanks!

Question is if prefix should only be present in application code or in DB (if it’s in DB, it’s no longer a UUID). If the former, check out: https://github.com/elixir-ecto/ecto/issues/2615#issuecomment-404155814

You can go with ksuid, this will add some timestamp info… but not user defined info. It is also larger than uuid. While not solving your problem, it shows You can merge prefix with uuid.