Introduction to CQRS and DDDD

556 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
556
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Warm-up
    DDD Building Blocks
    Classic Architecture
    Database Normalization
    Scaling Reads
    Scaling Writes
    The Single Source of Truth
    Breaking Free
  • Introduction to CQRS and DDDD

    1. 1. EXORCISM “THE PRACTICE OF EVICTING DEMONS OR OTHER SPIRITUAL ENTITIES FROM A PERSON OR AN AREA THEY ARE BELIEVED TO HAVE POSSESSED”
    2. 2. CQRS DISTRIBUTED DOMAIN DRIVEN DESIGN
    3. 3. Classic Architecture Client executes interactors Interactor modifies data and returns ViewModel
    4. 4. Step 1: CQS Command/Query segregation Commands - write data, void Queries - read data
    5. 5. Step 1: CQS public class SubmitAction : Interactor { public ShowLeadViewModel Execute(LeadActionDTO action) { var lead = ExecuteLeadAction(action); var viewModel = BuildViewModel(lead); return viewModel; } }
    6. 6. Step 1: CQS public class SubmitAction : Interactor { public void Execute(LeadActionDTO action) { ExecuteLeadAction(action); } public ShowLeadViewModel GetLeadInfo(long id) { var lead = GetLead(id); var viewModel = BuildViewModel(lead); return viewModel; } }
    7. 7. Step 1: CQS public class SubmitAction : Interactor { public void Execute(LeadActionDTO action) { ExecuteLeadAction(action); } public ShowLeadViewModel GetLeadInfo(long id) { return GetLeadViewModel(id); } }
    8. 8. Step 1: CQS Separated Query/Command logic Commands are executed asynchronously Queries are executed though a thin read layer
    9. 9. Normalization: 3NF vs. 1NF lead_id status_id queue_id contact_id campaign_ id assigned_t o_id 1043 1 2 241734 54 108 1044 3 5 241771 78 109 lead_id status queue contact_n ame campaign assigned_t o 1043 New Wait Yau Siong 1043 Contacted Converted Dimas Wijaya Saraya [03SEP2012] Gunggo_C A [060512] Alex Delors Mona Barbara
    10. 10. Step 2 Write model: 3NF Read model: 1NF
    11. 11. Step 2
    12. 12. Step 2: Events
    13. 13. Step 2: Events Multiple projections Scalable reads Decoupled storage mechanism RDMBS, Document store, Key/Value store, plain files (local or S3), Sharepoint List, Lucene, Cloud Search No need for NHibernate Profiler licenses
    14. 14. Step 2: Events
    15. 15. No reliable source of truth.
    16. 16. Step 3
    17. 17. Step 3: Events History
    18. 18. Step 3: Events History Every data change is logged Reliable source of truth Read model can be regenerated anytime Write model can be regenerated anytime
    19. 19. Step 3: Events History
    20. 20. Writes are not scalable.
    21. 21. Step 4
    22. 22. Step 4 var lead1 = { “leadId”: 15423, “customer_id”: “zubby@bubby.com”, “events”: [ { “type”: “lead_created”, “data”: {…}, “date”: “20131216T1242” }, { “type”: “lead_assigned”, “data”: {…}, “date”: “20131216T1342” }, { “type”: “activity_created”, “data”: {…}, “date”: “20131216T1432” }, { “type”: “new_lead_event”, “data”: {…}, “date”: “20131216T1522” }, { “type”: “activity_created”, “data”: {…}, “date”: “20131216T1432” } ] }
    23. 23. Step 4
    24. 24. Step 4: Event Sourcing
    25. 25. Step 4: Event Sourcing Infinitely scalable reads Infinitely scalable writes Audit data New business insights form past data Replay events for debugging and analysis Retroactive logic changes (=bug fixes) Lightweight backups NoSQL No deadlocks No DBA CHEAP!!!!!
    26. 26. CQRS Commands Events Event Store ViewModels / Projections
    27. 27. Questions?
    28. 28. DDD: Building Blocks Domain Driven Design Entity Aggregate Repository
    29. 29. DDD: Aggregate shoppingCart = { “id”: 1234, “items”: [{ { “product_id”: 123, “amount”: 1, “price”: 10}, { “product_id”: 123, “amount”: 1, “price”: 10} }] }

    ×