Search code examples
soasoftware-design

Best practice to use for having id: string or integer


I have a service which maintains the data of users. Can I just have userId as 1, 2, 3, etc. as integers which other services can call our account? Or is it some better practice to use string like UUID as ids?


Solution

  • Regarding performance, using string for IDs will indeed affect performance as when querying and analyzing data, matching two numerical values will be faster than matching two string, however you need to take into account that the solution(not limiting to the DB here) needs to support scaling.

    This means that at some point you might need to migrate or combine this database with something else, or maybe distribute to this database across multiple server, hence you would need something more solid, where you should be looking up on GUIDs (e.g. https://blog.codinghorror.com/primary-keys-ids-versus-guids/).

    TLDR: Use numerical values if you plan on keeping it a small DB for this service only, consider something more complex if you plan on scaling the project later on.