Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uuid in doubt #102

Open
hujun8610 opened this issue May 28, 2021 · 2 comments
Open

uuid in doubt #102

hujun8610 opened this issue May 28, 2021 · 2 comments

Comments

@hujun8610
Copy link

As mentioned in the gitbook, Returning response with uuid is a better practice. But backend developer usually use database to store data.As we know,It is not recommended to use uuid in the database,So how to solve the problem or haveing good suggestion.

@brandur
Copy link
Member

brandur commented May 28, 2021

It may indeed be worthwhile to amend this one slightly, even if only to make it clear that it's certainly not a slam dunk to use UUIDs.

The way I see it, UUID advantages:

  • Operational errors, even across different tables/resources, are incredibly difficult to do by accident. Two different resources in two different tables might share the ID 23, but when it comes to UUIDs, no entity shares an ID with anything else in the database. This has legitimately saved me a couple times as I've run an UPDATE against the wrong table (again, accidentally).
  • Scales well beyond a single master database.

Sequence/serial advantages:

  • Much improved data locality in that new data will land in the same nodes in the B-tree/pages on disk. If you have a table with a lot of INSERTs happening, sequences will be far more performant I/O-wise.
  • More human friendly in that it's easy to copy or remember a comparatively short integer ID compared to a UUID.

@geemus
Copy link
Member

geemus commented May 28, 2021

Good callouts. Do you think we should move from a recommendation to an explanation of the tradeoffs then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants