2
votes

I'm designing a photo sharing app (location based). I plan to use AWS Cognito for authentication/authorization, DynamoDB for persistent data, S3 for file storage, and Lambda + API Gateway for web services.

These are the key use-cases/access patterns (other than sign-up/sign-in):

  1. User creates a post: title, media, location (lat,lon)
  2. Users fetch a list of posts closest to their geo-location (newest first)

These are the Tables that I'm going to create:

Users table
hash-key=userID from cognito

Posts table
hash-key=userID from cognito
range-key=date
other-attributes=title, image-s3-path, ge-location

What is the best way to implement a query (perhaps with the help of adding LSI, GSI, or even more tables), so that the result is a collection of posts based on users's current location. Eg. show only posts within 10 km of radius, sorted by newest first.

2
Have you checked this: aws.amazon.com/blogs/mobile/… ?Tofig Hasanov

2 Answers

2
votes

You mentioned that your use case is users can retrieve posts closest to their location so that says that a good hash key for posts would be one that partitions data by spacial coordinates, not by user id.

I would look into geo hashing and using something like that for keys. You want to pick a partition key that gives good spatial partitioni g such that the posts are uniformly distributed, and there are relatively few of them in each partition key.

2
votes

I would consider using ElasticSearch, since it natively supports geohashing