I'm trying to learn proper DynamoDB modeling coming from a standard RDBMS background.
The relational database I am trying to denormalise is as follows:
TwoFactorDetail
- Id (pk)
- Status
- PhoneNumberId (fk)
PhoneNumber
- Id (pk)
- PhoneNumber
- Type
- AuthAttempts
Log
- Id (pk)
- TwoFactorDetailId (fk)
- EventType
- CreatedAt
My single table schema is as follows:
https://i.stack.imgur.com/8p3WY.png
As you can see, the same PhoneNumber can be used by many TwoFactorDetail entities.
Considering these two read / write patterns:
- Read TwoFactorDetail metadata including phone number, phone number type and attempts by TwoFactorDetail.Id
- Update PhoneNumber attempts by phone number
As you can see in the model, I am satisfying the read pattern with a known approach where the PhoneNumber entity linked to the TwoFactorDetail becomes an item within that partition. This means I can read all details for a particular TwoFactorDetail.Id with a single round trip to the db by using this condition: PK = "DET#12345" AND (SK = "DET" OR SK Begins with "PHO")
Now my question is how to keep PhoneNumber metadata consistent across partitions.
Ie. Because phone numbers can be shared across many two factor detail entities, and I would like to duplicate this data in each partition to ease reads, I am unsure how to update all items matching a phone number in a smart way so that I use the less amount of requests.