Pick a system of record.
What happens when these two databases disagree? Which one is right, which one needs correcting.
If you pick:
the document database as the system of record, then the RDBMS should track document id's.
the RDBMS as the system of record, then the document database should track the RDBMS entity id's.
Its possible that one datastore will be the system of truth for these bounded contexts, and the other datastore the system of truth for those bounded contexts.
Please don't say that both are the system of record for a given set of data. That path is paved in blood.
Whichever you do pick, the other is there to provide optimisations. Its faster, or more convenient than the other data-store for providing feature/property X.
This means a measure of duplication, and desynchronisation. You will need to consider how you are going to verify and maintain the integrity of the data.
Also the optimisation data-store will likely be behind the times and slightly out of date. This might be as little as milli-seconds, but it could be much longer... Is the staleness going to affect your business processes?
You should engineer the data structure to align with how you are using it.
If you are performing an elastic search storing a row ID can make sense. With that id:
- RDBMS lookups can be performed more optimally.
- Business logic that performs joins or record filtering client side can do so with less margin for error
- The id can be displayed to customers, or to error logs.
In these cases the data is by definition useful. It might even be facilitating the robustness or speed of the system.
Conversely if you place the id in there saying that one day it will be useful. Its not just useless, but actively slows down the system.
- Every document/record has to allocate extra storage, along with indecies, and therefore reduces overall query performance.
- Data transfer has to move extra data. This reduces the amount of bandwidth available for useful data.
- This data has to be stored and manipulated in the memory of the client (assuming its retrieved). This reduces the computational resources available to perform actually useful work, and might even make it harder to perform useful work when you start hitting the capacity limits.
If you are not sure which way to go, not writing code for it is usually the better option.
A part that isn't there is not going to throw exceptions, or misbehave, or cause you to work around it later.
The only exception would be if the part would be too expensive to add later. In which case: do you really really need it? and ask that question twice.