Should I use UUIDs for resources in my public API?

后端 未结 2 1353
南方客
南方客 2021-01-30 12:16

I\'m building a SaaS application and want to expose IDs for resources which are not tied to my current data storage implementation (Postgres auto-increment IDs). These Stack Ove

2条回答
  •  自闭症患者
    2021-01-30 13:10

    I think you might consider the four main options here:

    1. use the UUID as your database Primary Keys, but it could be more computationally expensive than using Long

    2. create an UUID to Long mapping layer, this way you can publish your REST resources, but maintain a clean database structure using Long PK

    3. create an Alternate Key column in your database tables in order to hold de UUID values.

    4. instead of using UUID you could have cryptographic IDs, generated on the fly using a custom seed for each customer and original PK. This approach imposes more execution overhead but could be interesting in some scenarios. The customer would have to use always encrypted data, since they will never have access to the seed or algorithm.

提交回复
热议问题