AWS most efficient way of finding datapoints with a particular tag (string value in a list)

Viewed 43

I have a very newbie question on AWS. Let's say that I am running a store that offers 1.000.000 different products. Each of the products have their own row in dynamoDB in a table named products. Now I would like to attach a list of tags to each product for example ['football', 'outdoor', 'sport' ... ], so that when the customer searches for sport products with that tag shows up in the results.

I am thinking of the best way to approach this in order to offer fast but also cost-efficient searches, I have so far thought of 2 viable options:

Option 1: Include a tags field for each product that takes a list of tags.

'product_3' -> ['football', 'outdoor', 'sport']

Option 2: Create a new table where the key is each tag and includes a field that takes a list of products instead.

'sport' -> ['product_1', product_3, ... ]

I am inclined to go with option 2 since it feels like it will render the faster search, but I want to double check that I haven't made any wrong assumptions of missed any other superior option.

Would also be great to have an infrastructure that worked with word2vec so that products related to the search word also shows up, even if they are not identical string values.

1 Answers

DynamoDB is a powerful and very useful database, but it is not designed for search. My suggestion would be to use the correct tool for the job.

The pattern that I've used successfully multiple times is to use DynamoDB Streams and Lambda to replicate a table to an Elasticsearch index.

You can then have that string set of tags on each item in DynamoDB and manage them their. Your nominal read when you know the item hash key can be done against DynamoDB. When you want to search you hit Elasticsearch and get all of the benefit and flexibility it provides for searching. One of those benefits being really good pagination compared to DynamoDB's API as well as the ability to sort based on other attributes.

Related