What’s this “Saga” thing that everyone is talking about? <ul><li>@andreasohlund </li></ul><ul><li>http://andreasohlund.net...
What is a long running process? <ul><li>“A long running process is a process whose execution lifetime exceeds the time to ...
Long running process Step Step Step Step Step Start End Start
The problem <ul><li>Holding locks for the duration of a long running transaction are more likely  </li></ul><ul><ul><li>To...
Two levels of transactions <ul><li>First level is a business transaction </li></ul><ul><ul><li>Does not comply to ACID </l...
Long Lived Transactions  Step Step Step Step Step Start End Business Transaction ACID ACID ACID ACID ACID
The anatomy of a step Step Get current state Store
Sagas vs Aggregate roots Saga AR Event Command Event Command
Sagas and bounded contexts Saga AR Bounded context Event Command External Event
The birth of a saga Bus DB Store state Saga message Saga instance Create Dispatch Send Saga  Persister Save
Existing sagas Bus Message Dispatch Send Save DB Load/Store Saga  Persister Get Saga instance State
State <ul><li>Remember what steps have been executed </li></ul><ul><li>Gets persisted between each step </li></ul><ul><li>...
Time <ul><li>Long running transactions </li></ul><ul><li>Time is a business requirement </li></ul><ul><li>Needs to be dura...
Sagas help throughput <ul><li>Can execute “steps” in parallel </li></ul><ul><li>Saga instances are not run in parallel </l...
Versioning <ul><li>Long running == high probability that new versions must be compatible with older state </li></ul><ul><u...
How do sagas wake up? <ul><li>Messages need to contain id:s for correlation </li></ul><ul><ul><li>Non technical </li></ul>...
What happens when they are dead? <ul><li>The big void </li></ul><ul><ul><li>state is no longer relevant </li></ul></ul><ul...
Shit happens <ul><li>Compensating actions </li></ul><ul><ul><li>You decide </li></ul></ul><ul><li>Retry of individual mess...
E-VAN  - Sagas
E-VAN  - Sagas
E-VAN  - Sagas
E-VAN  - Sagas
E-VAN  - Sagas
E-VAN  - Sagas
E-VAN  - Sagas
E-VAN  - Sagas
E-VAN  - Sagas
Upcoming SlideShare
Loading in...5
×

E-VAN - Sagas

1,547

Published on

My e-van presentation on sagas and how they are supported in NServiceBus

Published in: Technology, Design
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,547
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
51
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • LLT - Long lived transactions - Hector Garcia-Molina 87 Top level is a business transaction Does not comply to ACID Requires compensating actionsSecond level is acid compliantAnalyze the business to find the boundaries Add messages -&gt; in order to make each step as short as possible + forward movement only
  • Developers tends to do the same mistakes today
  • Top level is a business transaction Does not comply to ACID Requires compensating actionsSecond level is acid compliantAnalyze the business to find the boundaries Add messages -&gt; in order to make each step as short as possible + forward movement only
  • One way messaging only to keep transaction as short as possible More scalable and robust http://www.udidahan.com/2008/06/23/sagas-solve-stupid-transaction-timeouts/ Can execute “steps” in parallelSaga instances are not run in parallelUse locks in DB to ensure that
  • Not a hard rule Sagas are useful for other non DDD related things
  • Sagas operate within a BC Can react to events from other BC’s
  • Saga message handlers have state
  • E-VAN - Sagas

    1. 1. What’s this “Saga” thing that everyone is talking about? <ul><li>@andreasohlund </li></ul><ul><li>http://andreasohlund.net </li></ul>
    2. 2. What is a long running process? <ul><li>“A long running process is a process whose execution lifetime exceeds the time to process a single external event or message” </li></ul><ul><li>- Udi Dahan </li></ul>
    3. 3. Long running process Step Step Step Step Step Start End Start
    4. 4. The problem <ul><li>Holding locks for the duration of a long running transaction are more likely </li></ul><ul><ul><li>To be deadlocked </li></ul></ul><ul><ul><li>To experience infrastructure failures </li></ul></ul>
    5. 5. Two levels of transactions <ul><li>First level is a business transaction </li></ul><ul><ul><li>Does not comply to ACID </li></ul></ul><ul><ul><li>Requires compensating actions </li></ul></ul><ul><li>Second level is acid compliant </li></ul><ul><ul><li>Analyze the business to find the boundaries </li></ul></ul>
    6. 6. Long Lived Transactions Step Step Step Step Step Start End Business Transaction ACID ACID ACID ACID ACID
    7. 7. The anatomy of a step Step Get current state Store
    8. 8. Sagas vs Aggregate roots Saga AR Event Command Event Command
    9. 9. Sagas and bounded contexts Saga AR Bounded context Event Command External Event
    10. 10. The birth of a saga Bus DB Store state Saga message Saga instance Create Dispatch Send Saga Persister Save
    11. 11. Existing sagas Bus Message Dispatch Send Save DB Load/Store Saga Persister Get Saga instance State
    12. 12. State <ul><li>Remember what steps have been executed </li></ul><ul><li>Gets persisted between each step </li></ul><ul><li>Temporary storage of data </li></ul><ul><li>Serialize access to the same saga instance </li></ul><ul><ul><li>Unique index </li></ul></ul><ul><ul><li>Locking </li></ul></ul>
    13. 13. Time <ul><li>Long running transactions </li></ul><ul><li>Time is a business requirement </li></ul><ul><li>Needs to be durable and managed externally </li></ul>
    14. 14. Sagas help throughput <ul><li>Can execute “steps” in parallel </li></ul><ul><li>Saga instances are not run in parallel </li></ul><ul><ul><li>Use locks in DB to ensure that </li></ul></ul>
    15. 15. Versioning <ul><li>Long running == high probability that new versions must be compatible with older state </li></ul><ul><ul><li>Either patch DB </li></ul></ul><ul><ul><li>or write back compat code </li></ul></ul>
    16. 16. How do sagas wake up? <ul><li>Messages need to contain id:s for correlation </li></ul><ul><ul><li>Non technical </li></ul></ul>
    17. 17. What happens when they are dead? <ul><li>The big void </li></ul><ul><ul><li>state is no longer relevant </li></ul></ul><ul><li>But their children lives to tell the story </li></ul><ul><ul><li>Other entities gets updated to reflect the outcome of a saga </li></ul></ul><ul><li>todo: image black hole/gravestone </li></ul>
    18. 18. Shit happens <ul><li>Compensating actions </li></ul><ul><ul><li>You decide </li></ul></ul><ul><li>Retry of individual messages </li></ul><ul><li>Strive for forward recovery only </li></ul>
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×