3 interesting data techniques I've used to solve business problems
The year was 2014
- I was busy working on my first public API
- REST was having it's day in the sun
- I discovered a talk...
"Turning the database inside out with Apache Samza" by Martin Kleppmann
The only bit I remember

This is a basic version of CQRS
(Command and Query Responsibility Segregation)
We use this pattern in heaps of places with a payroll product.
Let's extend on this idea and look at some options
We could expire the data
| Employee ID | Payslip | Leave balance | Deleted? |
|---|---|---|---|
| 1 | 7 | 10 | true |
| 1 | 8 | 12 | true |
| 1 | 9 | 14 | true |
| 1 | 9 | 15 | false |
Was the edit to payslip 9 correct or incorrect?
We could state the changes
| Employee ID | Payslip | Debit | Credit | Running Total |
|---|---|---|---|---|
| 1 | 1 | 0 | 2 | 10 |
| 1 | 2 | 0 | 2 | 12 |
| 1 | 3 | 0 | 2 | 14 |
| 1 | 3 | 2 | 3 | 15 |
Now we can see the logic behind the changes
There's heaps of variations to this concept
We can even use it to deal with race conditions
| Shift ID | Approved Start | Approved End | Processed? |
|---|---|---|---|
| 1 | 9am | 5pm | false |
Set to true when the shift has been processed
Race conditions are the best
We start processing the job
Fetch the shift details from the db
Edit is made
Processed flag is marked as true and the edit is not processed
I love race conditions
| Log ID | Shift ID | Approved Start | Approved End | Processed? |
|---|---|---|---|---|
| 1 |
1 | 9am | 5pm | true |
| 2 | 1 | 10am | 5pm | false |
| 3 | 1 | 9:30am | 5pm | false |
We could process each change sequentially but that might be unnecessary
Race conditions = pure bliss
| Log ID |
|---|
| 1 |
| 2 |
| 3 |
Grab the latest version which is unprocessed and process the latest version
| Log ID |
|---|
| 4 |
| 5 |
| Log ID | Processed? |
|---|---|
| 1 | true |
| 2 | true |
| 3 | true |
Repeat when more changes come in
Questions?
James Harvey
Chief Software Architect @ foundU
3 interesting data techniques I've used to solve business problems
By James Harvey
3 interesting data techniques I've used to solve business problems
- 367