← Back to context

Comment by danpalmer

4 days ago

I saw some docs around this but it doesn’t seem to answer the main problem.

If you have users and posts, with posts having a userid field referencing users.id, and you shard the users table on id, how does it behave?

Now I request posts for a user id, is it smart enough to map the posts field to the users field? Where are posts stored? What if one user has all of the posts, now my data will be unbalanced across shards. Can I shard on post.id? If so what are the implications for querying joined to user?

The naive answer is to break foreign key integrity in the database. But it specifically says that pgdog doesn’t require sacrificing data safety.

You shard posts on posts.userid as well, same hashing function, same number of shards.