What is a DynamoDB stream?

Learn about streams in DynamoDB and how to use them.

An interesting and very common use case that we could have is the need to be able to detect the changes happening in a database. Once these changes are detected, operations can be performed with them.

One approach could be a batch process that would involve querying the database at regular intervals. However, this would be inefficient as it could affect the performance of the database with heavy executions such as a scan. Other than that, this process would also consume RCUs. Finally, the concept of real-time could not be handled in this situation either. Addressing these issues, DynamoDB offers us a better solution, and it is the one we’re going to discuss in this lesson.

What are streams?

Streams are a feature that DynamoDB offers to track the changes that are occuring in a table. When any kind of modification happens in DynamoDB, it will emit an event with information regarding the event that occured. To recall, the three types of changes that we could have are insert, update, and delete. Therefore, when any of these actions occur, DynamoDB triggers an event indicating that something has just happened.

Events could contain all the information necessary to carry out an action that we want. For example, validate a modified record, store the information in a file system, send a notification and so on. Depending on your use case, you could have the complete record or just the keys to them.

It’s interesting that DynamoDB guarantees that the events are sent in the same order in which they occur. This is an important feature to take into account when you’re required to process events in the same order in which they occur in a table.

How do streams work?

When the DynamoDB Stream functionality is activated, we need to make use of another AWS functionality called Lambda, which is a piece of code triggered by an event that allows us to decide what to do with the information that is arriving.

As DynamoDB emits events based on changes that are occurring in a database, the events are received by the Lambda function.From here on, it’s possible to manipulate them and decide what to do with the incoming information. For example, it could be stored in another database, in a file or, simply, in a log. The image below shows how this integration works:

Get hands-on with 1200+ tech skills courses.