Regarding the first part of my question: I was recently asking myself what are the benefits and trade-offs of having a unique identifier for certain tables in a relational database. Just as an example, the Facebook (FB) Graph API allows to fetch different types of objects such as "Users", "Events", "Pages", etc. using the same URL, e.g https://domain/251906384206 returns an object of type "Event" whereas https://domain/195466193802264 returns an object of type "Group".
What is the benefit of this approach compared to providing a less "generic" API, one which would be used in this way: https://domain/event/251906384206 or https://domain/group/195466193802264. In this case, a similar identifier might be used for different objects types because each object type has it's identifier scope.
Regarding the second part of the question: What are the options for implementing a globally unique identifer?
Two options that come to my mind are:
Using an inheritance-based approach (table-per-class, single table, etc.). Assuming a table-per-class approach is used (super table contains unique identifier as primary key only, sub table representing object type contains same indentifier as super table and additional data), joins are required between super and sub table which seems to scale badly because the super table becomes a bottleneck?
Providing a table with 3 columns, containing
- unique identifier,
- object type specifc primar key, and
- table name.
Additional tables per object type containing a column referencing the unique identifier as foreign key. Each object type specific table has it's own primary key scope.
Both approaches would allow to provide a generic API like the FB API mentioned above. The second approach would allow to use object table specific primary keys internally and to expose the globally unique identifier only. However, if a global unique identifier might be used internally, the second approach would require a join as well.
Are there any experiences regarding pros/cons of a globally unique identifier and what are the best practices for implementing it?