Ad

What Is The Correct Way To Propogate Changes In Connected DynamoDB Tables

I'm a beginner in Serverless and dynamoDB. My use case consists of two tables Trips and Routes. Trips table consists of these parameters {id, Route, Cost, Distance, Time}. Routes table consists of these parameters {quantity, Rate, From, To }.

Cost param in the Trips table is calculated by quantity * Rate params from the routes table. Every time a trip is created/edited I fetch the value from the table and store the new value as Cost param of trips table.

The issue arises when someone changes the quantity or rate parameter in the Routes table, how do I propogate this change to Trips table? Currently I'm updating the Cost Parameter everytime someone updates Routes, is there a more efficient way?

Ad

Answer

You can use dynamodb streams. Any change in the route table can be captured in these streams and processed to update the corresponding object in your Trips table. DynamoDB does not support aggregations unfortunately otherwise the cost field could have been computed while querying the object which would have been a lot easier.

Ad
source: stackoverflow.com
Ad