Please help me understand this data sharing concept related to micro-services, I am trying to learn the best practices.
Suppose I have a Lambda function (micro-service) A that is designed specifically to perform CRUD operations on a DynamoDB table (NoSQL). I have use cases that trigger this function to update specific items in the table.
I have another micro-service B that will need to read and write to the same database table. If I were to have this micro-service B directly perform CRUD on the DynamoDB table, that would be a bad idea since now A and B are both configured to operate separately on the table so ACID guarantee is lost. (correct?)
To prevent this, would this be the best solution? :
- Get rid of micro-service
Baltogether. - Whatever event would have triggered
B, have it triggerAinstead to perform the corresponding database CRUD operations.
Would this maintain ACID guarantee?
I'm not sure how 2 microservices violate ACID properties. Below are the properties and a description of how having multiple producers affects it.
Atomicity
Transactions are often composed of multiple statements. Atomicity guarantees that each transaction is treated as a single "unit", which either succeeds completely or fails completely: if any of the statements constituting a transaction fails to complete, the entire transaction fails and the database is left unchanged.
Having two producers does not break Atomicity
Consistency
Consistency ensures that a transaction can only bring the database from one consistent state to another, preserving database invariants: any data written to the database must be valid according to all defined rules, including constraints, cascades, triggers, and any combination thereof.
Having two producers does not break Consistency
Isolation
Transactions are often executed concurrently (e.g., multiple transactions reading and writing to a table at the same time). Isolation ensures that concurrent execution of transactions leaves the database in the same state that would have been obtained if the transactions were executed sequentially.
I think you believe Isolation is where your issue is, however all writes to DynamoDB are strongy serializable and thus isolated
Durability
Durability guarantees that once a transaction has been committed, it will remain committed even in the case of a system failure (e.g., power outage or crash).
Having two producers does not break Durability
Wiki