Non SST specific question. I have the following da...
# help
d
Non SST specific question. I have the following data in DynamoDB
Copy code
comicSeries: { title: 'whatevr', active: true/false }
and then customers
haveMany
subscriptions that look like this
Copy code
subscriptions: {[{ comicTitle: 'whatevr', active: true/false }]}
So a comic or subscription can be
active
. This works great 🎉 When a comicSeries becomes inactive, I want to deactivate each subscription for each customer. Realistically, I can just do this in a lambda. But isn’t this technically a use for a queue? My question is, how would you handle this in a robust way?
t
there's actually 3 separate states here 1. Comic is active 2. Subscription is active 3. Can a user access the comic (need 1+2) to be true. You can store 1+2 as you do now and just compute 3 whenever it's requested If you do want to precompute and store the 3rd value yes you would need to bulk update things in a queue
but there's actually a lot of ways to structure this depending on your needs
you could model customer subscriptions as pk = comicID and sk = customerID, then deleting it is simpler since it's just deleting all items in a partition
s
What are you access patterns? How do you need to access the data?
d
I dont think this is a data modeling question…
For my take, the most robust way to handle events is to: • Have a centralized event depository of some sort (Eventbridge, SNS). • Have a centralized “event publisher” lambda subscribe to every DynamoDB table stream, and publish to the depository. • Have any other interested lambda subscribe to the depository, and act accordingly.
there are, of course, lots of options in between this and a lambda, but you said robust!
s
Hmm, I guess I read the question as "how do I represent deactivated subscriptions if my data is modeled this way?"
d
I'm sorry I was unclear. Derek is correct. The question is how to deactivate all the comic subscriptions when the comic changes state to inactive
d
A queue would work just fine, allow retries, and enable you to have a DLQ, and is much easier if you are only ever going to do this once. If many times, consider above.
d
Gotcha. Ya they'll potentially go from active to inactive and back again. So I'll review those choices. Thanks so much Derek