0

I am having a problem to solve this issue in DynamoDB. I need to create a table of sellers and their location expressed as Long and Lat attributes.

Now if I have a Buyer. I need to return all sellers within 1 Mile radius of the buyer.

How do I structure my seller table, and if I need a GSI what do I do there? Assuming that I have a formula that works out the starting long/lat and ending long/lat. So I need DynamoDB to return any sellers located in between the lower and upper boundaries.

Also what partitioning logic do I need to adopt?

Thank you in advance!

Bluetoba
  • 885
  • 1
  • 9
  • 16
  • If you just google it and many results show up. Its not very easy to do. There are some libraries for it. Logic is explained here https://aws.amazon.com/blogs/mobile/geo-library-for-amazon-dynamodb-part-1-table-structure/ – Can Sahin May 09 '18 at 13:20
  • Thanks CanSahin. One other part of my question is not really on geohashing. But on how does DynamoDB returns a multiple set of records not related to the partition key? It's taken me this long but I may have now come to an understanding that DynamoDB cannot be queried to return a set of records easily, like in SQL queries. For example if I have a products table and I want to search by category = Kitchenware, regardless of the partition-key. Any idea? – Bluetoba May 09 '18 at 22:18
  • No you cannot query without a partition key. Its NoSQL. The whole point is that. You have to use Global Secondary Index at worst. The only things you can query is the indexes. But there is SCAN operation with starts reading all the records and check if they met condition. Can be very expensive and inefficient. – Can Sahin May 10 '18 at 05:54
  • I hear this a few times, that you can use GSI to perform a query on the whole table. And let's say I have created a GSI just for that purpose. When querying the GSI, I still need to follow the same query structure of performing an equal condition on the partition-key, don't I? Therefore, without doing a full table/index scan; I can never perform a query that returns multiple records? For example records in products table with category = Kitchenware? What is the technique people do to overcome it in DynamoDB then? – Bluetoba May 10 '18 at 21:14
  • GSI partition key dont enforce uniqueness. Thats a gotcha. If you have GSI on attribute 'category' you can have multiple records having 'Kitchenware'. When you query GSI it will return all the items matching 'Kitchenware'. – Can Sahin May 10 '18 at 23:50
  • Thanks CanSahin. However, if there are only say a dozen types of categories and there are millions of products. (Not a real world example). Therefore, only low cardinality. I hear that they are bad partition distribution, and hence bad design. Is that correct? – Bluetoba May 11 '18 at 07:06
  • Yes it called hot partitioning. Its a bad design. There are techniques to avoid that. Well its bad application logic anyway. Why do you wanna query obtain hundered thousands of items. If categories are such you should come up with something. There are gold information here https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/best-practices.html . You will see what you can do with the indexes in details. Definetly read it :) All answers are there ;) – Can Sahin May 11 '18 at 08:54

0 Answers0