Coder Social home page Coder Social logo

Comments (6)

ericelliott avatar ericelliott commented on June 16, 2024

If you care about this for ID lookup optimization, isn't it possible to customize the sort criteria for ID lookup?

If you care about this to sort entities by creation time, you should have a separate created_at field in your database record and sort on that field, rather than by ID.

In general, an ID should be used strictly as an identifier. I've never encountered a situation where it's a good idea to let the ID serve double duty and be used to encode other information as well. Yes, cuids happen to store creation time, but only incidentally, not as an interface contract, and it's creation time that shouldn't be relied on for accuracy or data validation needs.

from cuid.

ericelliott avatar ericelliott commented on June 16, 2024

Rule of thumb (for all IDs, not just cuid): if you're trying to parse the ID to extract any data other than the whole ID itself, you should probably rethink your design.

from cuid.

maberer avatar maberer commented on June 16, 2024

Thanks for the advice, trying to keep my IDs clean... as a last resort, parts of an ID could be separated e.g. with dashes... some do this by having a shard key combined with the ID so something like:

shardID-CUID
...forming the complete ID

Not sure what your thoughs are with something like that... but I assume that it should be avoided as well.... have seen implementations using something like that.

from cuid.

ericelliott avatar ericelliott commented on June 16, 2024

It should be avoided, yes. Not least because different apps have different sharding requirements. For example, some apps shard users or content by region rather than simple bit bucket mapping. Lots of apps mix sharding strategies based on the use case for the specific entity type. It definitely does not make sense to mix sharding concerns into the ID generator itself.

from cuid.

maberer avatar maberer commented on June 16, 2024

ok thanks

from cuid.

ericelliott avatar ericelliott commented on June 16, 2024

👍

from cuid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.