0

DynamoDB is the database solution, I'm using to store my items. It's a NoSQL/Document database and I got a real problem on real-time updates of items.

First, the saved format is like

{
  expiredTime: 'Yesterday(this is a epoch or formatted string)',
  state: 'enum values EXPIRED and VALID'
}

The problem is I need accuracy and real-time compatible data for read requests, but DynamoDB has not supported that type of trigger.

So, I thought about an idea of a subscriber of read requests in my code, then if read requests contain expired time is the past. The subscriber will update the state of items. Any function calls the items will receive altered state (corrected) even the listener haven't finished.

Is this considered bad practice? Because I must not allow any read requests except the one attached a subcriber.

1

Yes, what you propose is a bad practice. All your read operations are now potentially write operations as well. This means that they will have the same concurrency implications as write operations and you will have to deal with parallel and potentially conflicting updates of the same document.

A better solution is to not store attributes that can be calculated from the values of other attributes, like the state attribute that can be calculated from expiredTime and the current or retrieval date.

  • What about I wait for the result of the read requests, and notify the subscriber about the result for write operations. – trmaphi Jul 11 at 10:43
  • @trmaphi: What if multiple (independent) users try to read the same data at the same time? How are you going to ensure that the "read subscribers" don't form a performance bottleneck and at the same time don't overwrite/mangle each other's updates? – Bart van Ingen Schenau Jul 11 at 10:49
  • I'm thinking of some type of isolation level for the "read subscribers". Once an item is updated, the next "read subscribers" will at least not fired with the same item. – trmaphi Jul 13 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.