0

I have the following AWS AppSync/Amplify model

type Event @model {
  id: ID!
  name: String!
  ticketsSold: Int!
  moneySum: Int!
}

The ticketsSold property must reflect the count of orders with eventId = X. moneySum must represent a SUM of all the orders ticket price with eventId = X.

There are 2 options (or more?) to consider:

  1. With every putItem (createOrder mutation), update the correct event row with the new count/sum
  2. Do a query/scan of all the orders with eventId = X via an AWS Lambda resolver

There are some pro's and con's with each of the options. With option 1 there is the possibility to get out of sync if multiple people order at the same time (transactions?). With option 2 there is the drawback that scanning is very expensive & slow...

The events are shown on the home page of a ReactJS app with the ticketsSold and moneySum shown as a preview and on the detail so it will get fetched "a lot".

Suggestions? Thanks a lot!

1 Answers1

1

I would go with option 1 using streams from your ticket DB into a lambda that updates some table with the aggregated info. It's going to be pretty fast and way cleaner than endless scans. I use this to aggregate lambda usage for users, logging lambda runtime into a table that can be instantly queried for the total. Works great.

cyberwombat
  • 38,105
  • 35
  • 175
  • 251
  • How do you handle transactions? As multiple triggers can be executed at the same time? Firebase has transactions for instance, not sure how to do this with AWS services? – Pieter Moeyersons Nov 20 '20 at 15:55
  • I don't see transactions would be an issue The appropriate table streams (tickets?) reflect the valid data you care about. Depending on your scenario you can have insert/modify/remove events handled by the aggregating lambda. The lambda can receive up to 1000 stream records in a single batch. – cyberwombat Nov 22 '20 at 18:00