Actual business logic will not be disclosed. Some details may be simplified, and service names or identifiers may be replaced or generalized.
The case
try and error
What I learned
Evaluate
It's easy to design a system without any limitation we colud import data one by one
Source Bill
Procceser
Consider time cost and risk
We should batch import data
Here comes the problems:
1. Two different souceBills might effect same record in our db
2. If the operation happend in the same time, it will occurs race condition
Race Condition #1: Duplicate Insert
Race Condition #2: Lost Update
Solutions
Idempotent Upsert
not enough
Resolve duplicate insert, but did not resolve Lost update issue
Transaction-Level Advisory Lock
One more thing
Integration test
By Jay Chou