|
|
|
|
|
by rglullis
1894 days ago
|
|
The way to fix that is to remove state altogether. 1. Balance is not a simple variable, but the sum of all credits and debits to an account
2. A fee is a charge record in your database
3. This fee has a database constraint that you can have only one record per month
Now you can run the script that charges dormant fees as often as you want. |
|
Practically speaking, this narrows your "transaction window" significantly - instead of:
With a potentially long transaction spanning from 1-5, you do this: Of course if "Do work" is very expensive, you can bring back in "Check to see if work has already been done" as an optimization, but for many simple CRUD examples, it's actually /cheaper/ to learn that the work has already been done via the conflict check failing than via an explicit pre-flight check.