DEV Community

Cover image for Why You Shouldn't Use DynamoDB Filter Expressions And What To Use Instead
Uriel Bitton
Uriel Bitton

Posted on

Why You Shouldn't Use DynamoDB Filter Expressions And What To Use Instead

Last Friday I talked about DynamoDB on Zac's AWS Show.

Here's some of the value I shared πŸ‘‡

πŸ‘‰ Why you don't want to use FilterExpressions

FilterExpressions should be a last resort solution.

They only filter the results after all items were fetched, losing the real benefit of filtering.

How do you filter then?

Use Sort keys...

πŸ‘‰ How to use powerful filtering on your data

Sort keys give you the opportunities to design for powerful filtering and sorting.

In the video below I explain briefly how to overload your sort key to allow for this efficient filtering.

πŸ‘‰ The 2 most important query methods to understand

These are the:

  • begins_with() method: the basis of filtering
  • BETWEEN method: enables range type filtering

I show nice examples of these in the talk.

πŸ‘‰ How GSIs work in DynamoDB

GSIs allow for additional access patterns.

A typical use case for a GSI is to create an inverted index for 1-many relationships.

E.g. If your base table lets you get all students enrolled in a course, your inverted GSI index lets you get all courses that a student is taking.

πŸ‘‰ The single table design

Finally, i teased the single table design, the motivation behind it and some good use cases.

Using one table instead of many is usually a better idea with DynamoDB.

It offers much faster queries.

The data that you query together should be stored together.

It also offers lower costs if you are using provisioned capacity.

That's it!

If you missed it you can watch the recording here:

Youtube Link

Top comments (0)