As I understand there are no foreign key constraints in Dynamo.
We have users, groups.
Since users and groups are tightly linked to each other, they are being stored in the same table in this particular use case. But generally speaking, it could be attributed to the same table or a different table.
Forex:
A request to add a user to a group with a given groupId.
A request to add a site to a group.
What's the best and optimized way to check that the given groupId that we will be adding to the user actually exists. The same goes for the site with a given siteId that needs to be added to a given group.
Do we send out a checkIfExists dynamoDB query for every such field before inserting the data in the DB? That sounds unoptimized and ugly. How can this be approached in a better way?
This is likely the solution. I think you think it sounds "unoptimized and ugly" because you're not used to doing it, instead relying on the database to do it for you. What would you do if you needed to make sure some something that wasn't in your database exists? For example, say you use a 3rd party API for something, and you need to be sure there is a record there before creating your record? You'd have to make a request to that service first. What DynamoDB is doing is forcing you to include your business logic in your code. As for the performance, a request for a single item in DynamoDB typically takes less than 10ms, and if that's not fast enough you can use DAX and get that down to under 1ms in most cases.