Schema Design advice

Im working on a Flutter app that tracks matches for an amateur, nationwide sports league. Im using flexible sync and the main tables I have are:

User : Read/write own role.
Player (Read all role. Stores public info such as name, image url, etc.)
Match (Read/write own roles. Stores both player IDs and match details)

I have all of this working except I’m wondering if my approach is right when it comes to syncing players.

Right now each User is subscribed to all matches they have played in, with player 1 being the “owner” in terms of write permissions. At startup
I update subscriptions. Once syncing is complete for matches, I build an opponent list based on the current user’s matches and manually subscribe to each opponent so they are synced locally. This allows me to provide a list view with all of their matches and opponent’s info…even when offline. With that setup, I’ll have to update this subscription list every time a match is created or deleted to keep things in sync. However, from what I’ve read, you shouldnt update subscriptions often due to a performance hit. I’m not sure what that “hit” will be.

A couple of other ways I’ve considered:

  1. Have each user maintain a list of players that gets updated when a new match is created. Then under read roles, call a server function to allow/disallow reading of only the players a user has played against. Drawback: That list is essentially unbounded and could get quite large over time. Otherwise, I think this would work but I havent tried it yet.

  2. Embed (duplicate) player data in each match. Drawback: duplication of data that won’t update when the player changes their name, image, etc.

  3. Syncing with all players. Drawback: That could be thousands of players over time so bandwidth, space and performance concerns.

Is there a 4th option?

The bottom line is that I want each user to have their matches and opponents they played in those matches subscribed to in the most efficient way.

Any tips would be appreciated!

Your description leaves a good deal unclear, especially about the nature of a subscription. However, your use case sounds like a classic relational model.

As a thought exercise you can try to figure out how you would set things up in a RDBMS (relational database management system) such as MariaDB / Db2 / Oracle / MSSQL etc.

Then work back from there towards a MongoDB mapping exhibiting the least amount of:

  • duplicate data
  • copying/updating
  • lookups
1 Like

First, thanks for the reply.

When I say subscription I’m referring to Atlas Flexible Sync subscriptions ( Based on your response I think I posted this to the wrong MongoDb group since anyone who deals with Atlas Device Sync is very familiar with subscriptions. I’m going to check the other groups and see if there’s a more accurate place to post this question.

Thanks again :slight_smile:

I don’t know, @Shane_Bridges , if the problem is the Forum group you posted in or perhaps rather that I’m particularly clueless :slight_smile: Yes, you might try MongoDB Atlas App Services & Realm or one of the other Atlas-specific Categories on this Forum.

Thanks, I should have tagged the device sync group so thats on me :slight_smile: I just did a similar post there with some more details.

1 Like