![]() Some existing solutions solve this problem and can be utilized in our applications. It will take a lot of time, effort, and a couple of PhDs. We cannot rely on probability laws unless we’re a casino.Ĭonclusion: we should not reinvent the wheel for globally unique ID generation algorithms. For big, distributed data-intensive systems, this approach is not acceptable. We can only hope that our generated IDs won’t clash. The problem with this approach is that it does not guarantee uniqueness. For example, to create a 64-bit ID, we can use the first 32 bits of the timestamp and the last 32 bits of the random number. Let every application instance generate a unique ID using a random number generator, and that’s it! To make it better, we might think of using a composite structure - let’s append timestamp (in milliseconds) to the beginning of the random number to make our IDs sortable. This is a straightforward and naïve implementation for decentralized ID generation. When it comes to ID generation in distributed applications, we need to decide which algorithm to use to guarantee uniqueness and sound generation performance. In this article, we will discuss two fundamental topics for client-generated ID strategy: how to generate a unique ID value and when to assign it. This strategy gives us more flexibility in terms of ID generation algorithm and format and allows batch operations by its nature: ID values are known before they are stored in a DB. Those are the cases where client-based ID generation (or, rather, non-DB-based) comes into a stage. ![]() Also, this approach does not work for distributed applications where we can have several DB instances deployed on several data centers in several time zones. This principle might become a challenge: we depend on a particular storage system, so switching to another (e.g., from PostgreSQL to Cassandra) might be a problem. All the ID generation strategies described in the article are based on one fundamental principle: there is a single point that is responsible for generating IDs: a database. In the previous article, we discussed server-generated IDs for JPA entities. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |