We are familiar with transactions in databases, messaging systems and caches. When messaging system works fine, but database transaction fails - we are in big trouble! How to make all this guys work as a team? - What need to be used is distributed transactions or compensation mechanisms. On this talk we see both approaches and discuss how to take advantage of them when we are building Microservices architecture.
See code examples here: https://github.com/kslisenko/distributed-transactions
8. 8CONFIDENTIAL
Transaction log
• Always in known state
• States and transitions are logged
• Log can be used for recovery
DATABASE TRANSACTION AS STATE MACHINE
begin in progress
commit
rollback
INSERT UPDATE DELETE commitbegin
12. 12CONFIDENTIAL
ACID TRANSACTION GUARANTEES
Consistency
Data always in valid state
Constraints
Isolation
Visibility of concurrent actions
Locking
Durability
Changes become permanent
Write-ahead log
Atomicity
All or nothing
Write-ahead log
42. 42CONFIDENTIAL
Application server
JTA AND XA SPECIFICATION
Resource
manager
Resource
manager
Resource
manager
Transaction
Manager DB
JMS
?
Java
application
JDBC
CUSTOM
43. 43CONFIDENTIAL
JTA AND XA SPECIFICATION
Resource
manager
Resource
manager
Resource
manager
Application server
Transaction
Manager DB
?
Java
application
begin
begin
begin
44. 44CONFIDENTIAL
Application server
JTA AND XA SPECIFICATION
Resource
manager
Resource
manager
Resource
manager
Transaction
Manager DB
?
Java
application
update
update
update
45. 45CONFIDENTIAL
Application server
JTA AND XA SPECIFICATION
Resource
manager
Resource
manager
Resource
manager
Transaction
Manager DB
?
Java
application
prepare
prepare
prepare
46. 46CONFIDENTIAL
Application server
JTA AND XA SPECIFICATION
Resource
manager
Resource
manager
Resource
manager
Transaction
Manager DB
?
Java
application
commit
commit
commit
47. 47CONFIDENTIAL
TM does all the job for us, but:
• Needs too many messages
• Doesn’t scale well
• Not all vendors support XA