'DynamoDB Data Model for location tracking
I am working on a project that involves location tracking between users. I need some help figuring out how best to structure the data. We are using AWS and our options are DynamoDB (which is preferred) or RDS.
The problem we're running into is that we need connected users to easily have access to the location of their connected friends. We want to minimize DB calls to do this.
Here's a layout of what we have/need:
- User 1 is connected with User 2 and User 3.
- User 1 moves and an app on their phone sends a location update to the database when they stop moving (so when they get to their location).
- Users 2 and 3 need to know when User 1's location is updated.
Originally we thought to set up the data as so:
User 1 {
"id": "id1",
"name": "User 1",
"connections": [
"User 2": "id2",
"User 3": "id3"
]
}
Users 2 and 3 would look similar. The problem with this structure is that in order for a user to update all of their connections' locations, they would need to make separate queries for each id in their list.
In RDS we would use a connections table and query for any connections for the given user, then we'd return all items, in the example above with DynamoDB we would have to make individual queries for each connection.
Does anyone know of a way we could restructure the DynamoDB data to allow us to run 1 query to get the locations for all of a user's connections without needing to update the location in multiple places?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
