3 ms·
One of the biggest learnings of our org was to prefix tokens with the entity type. It's helped immensely. entity-type:RANDOM_TOKEN * Helps in migrations, espe
by echelon 6y ago
One of the biggest learnings of our org was to prefix tokens with the entity type. It's helped immensely.
entity-type:RANDOM_TOKEN
* Helps in migrations, especially complex ones where you split up entity types.
* Identities what tokens are so people can look them up if they see them in logs.
* Polymorphic relationships can delegate to the appropriate owning service easily without additional bookkeeping.
You can also encode other stuff in the token entropy, too, such as the author DC/region for active-active setups where you need to forward the request to the source of truth in the brief window where the other regions don't know about it yet.
- 11235813213455 6y agothat's how Stripe prefixes their IDs too, depending on what type of entity it is. Makes debugging, docs, .. easier
- fiddlerwoaroof 6y agoI’ve always thought that a Java-style reverse domain name format (or, perhaps, URLs) is a great way to encode IDs: com.foo.bar.Person:0000-11111-22222-33333 or whatever. That way, any code that logs IDs or transfers IDs across the network gets tracing “for free” and, when you see an ID in a bug report, you can use it to help focus the investigation.
- ljm 6y agoRuby/Rails has this in the form of GlobalID[1]. To be honest I haven't seen it used outside of whatever Rails itself automatically does, but the concept is there. [1]https://github.com/rails/globalid https://github.com/rails/globalid