Identities

We mentioned username or email as an identity of users in the system, but what can be used as an identity for objects? In real life, many objects are already identified. Most common identity is an item serial number. Complex objects like smartphones, TV sets, computers, and cars have unique identifiers that help manufacturers to know in what configuration these objects were produced and therefore provide better support. Also, due to a significant price of such objects, they are usually tracked individually.

However, when we talk about our system, most of the time we need to use our own identity. The only important rule is really that all entities need to be uniquely identified. There are a few ways to get such an identity, and you might already be familiar with some. Probably the most frequently used method to get unique identities (later referenced as ids) today is to use unique database keys. It is because most systems out there are data-oriented and designed with persistence-first in mind. Such a system will not work without persisting stuff to a particular database.  Such method has at least one definite advantage - such ids are usually numeric and incremental, so it is straightforward to dictate such id over the phone. But the most significant disadvantage comes from the id source - the database must be present to get such identity even if later in the flow the system will decide not to accept the object and drop it instead, so it never gets persisted. Most of the experienced developers have seen weird constructs in the code where an empty or dummy row is being inserted to some table to get an object id and later such row either needs to be populated with real values or removed. Such an approach creates a whole load of issues, and we will not be using it.

Instead, we will use generated unique ids. Because we would prefer not to use any infrastructure to create our ids, we will use one reliable method and identity type - a globally unique identifier (GUID), wider known as a universally unique identifier (UUID). Such id can be generated using current time and some information about the computer, where it is produced. There is a very high probability that such id is globally unique. When using GUIDs, we can generate identities for objects before touching any infrastructure and therefore, for example, create references to an object that only exists in memory.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.190.175