Page
1
Mastering Domain-Driven Design Collaborative modeling with domain storytelling, event storming, and context mapping
Page
2
Mastering Domain-Driven Design Collaborative modeling with domain storytelling, event storming, and context mapping Annegret Junker www.bpbonline.com
Page
3
ii ■ First Edition 2025 Copyright © BPB Publications, India ISBN: 978-93-65892-529 All Rights Reserved. No part of this publication may be reproduced, distributed or transmitted in any form or by any means or stored in a database or retrieval system, without the prior written permission of the publisher with the exception to the program listings which may be entered, stored and executed in a computer system, but they can not be reproduced by the means of publication, photocopy, recording, or by any electronic and mechanical means. LIMITS OF LIABILITY AND DISCLAIMER OF WARRANTY The information contained in this book is true to correct and the best of author’s and publisher’s knowledge. The author has made every effort to ensure the accuracy of these publications, but publisher cannot be held responsible for any loss or damage arising from any information in this book. All trademarks referred to in the book are acknowledged as properties of their respective owners but BPB Publications cannot guarantee the accuracy of this information. To View Complete BPB Publications Catalogue Scan the QR Code: iH ■■ s www.bpbonline.com
Page
5
iv ■ About the Author Annegret Junker is Chief Software Architect at codecentric AG in Germany, who has an experience in software development for over 30 years. She worked in different roles and domains, such as automotive and insurance. Moreover, she is especially interested in Domain-Driven Design, microservices, and APIs. Annegret talks regularly at conferences and publishes in leading journals. She is working on a large integration project and defines APIs for partners. Annegret holds a PhD as an engineer.
Page
6
■ v About the Reviewer Dmitrii Porozhniakov is a software engineer with over a decade of experience contributing to impactful projects at leading technology companies. Throughout his career, he has worked in roles that demanded technical expertise and strategic thinking, developing systems that are scalable, efficient, and innovative. In his current role at Meta, Dmitrii focuses on backend development and cross-team workflows, playing a key part in initiatives that enhance data transparency and service understanding. Previously, he has played pivotal roles in designing robust payment infrastructures, streamlining large-scale data operations, and building scalable architectures that support millions of users. His contributions have consistently addressed complex technical challenges while aligning with broader organizational goals, ensuring seamless performance and long-term reliability. In addition to his professional achievements, Dmitrii is the author of several articles on software development, sharing insights on architecture, processes, and industry practices. His work reflects a thoughtful and practical approach to solving modern engineering challenges.
Page
7
vi ■ Acknowledgement I want to express my deepest gratitude to my family and friends, especially my brother Bernd and my lifelong friends Stefan and Stefan, for their unwavering support and encouragement as I wrote this book. I wrote it especially for my late husband, Stefan, who I will always miss. Moreover, I am grateful to BPB Publications for their guidance and expertise in bringing this book to fruition. Revising this book was a long journey, with valuable participation and collaboration of reviewers, technical experts, and editors. I would also like to acknowledge the valuable contributions of my colleagues and co workers during many years working in the tech industry, who have taught me so much and provided helpful feedback on my work. Moreover, I would like to thank my colleagues at codecentric AG for their support and the time they offered me to write this book. Finally, I would like to thank all the readers who have taken an interest in my book and for their support in making it a reality. Your encouragement has been invaluable.
Page
8
■ vii Preface Writing software is a challenging task in all phases of design and implementation. It is not alone in writing code; it is about understanding each other. Developers need to understand business experts, business experts need to understand software architects, solution architects need to work with enterprise architects, etc. Moreover, the problems we solve nowadays in software are intrinsically complex. We need to tackle this complexity by applying Domain-Driven Design, as described by Eric Evans over twenty years ago. Meanwhile, we know methodologies and workshop formats that allow us to create and modernize software in a highly collaborative way. A comprehensive process that emphasizes collaboration and engagement of all stakeholders is presented in the book, from the first ideas up to the implementation of events and restful APIs. This book introduces the process as Synergetic Blueprint and discusses its application using multiple examples. Chapter 1: Introduction to Domain-Driven Design - This chapter discusses the history of this approach, the complexity of modern software applications, and how to tackle this complexity. Chapter 2: Introduction to the Example Online Library - This chapter introduces an online library used as an example throughout the book to explain the single steps of the design process. Chapter 3: Why Strategic Design - This chapter discusses the influence of software architecture on a system and how to achieve team independence. Organizational dependencies are discussed when talking about Conway’s law. This discussion leads to how to reach better software and what better software means. Chapter 4: Bounded Context and Domain - This chapter introduces the terms domain, subdomain, bounded context, and aggregate. The patterns in strategic design are discussed. Chapter 5: Domain Storytelling - This chapter introduces domain storytelling as a workshop format. It discusses the domain story of the online library and its visual glossary and gives recommendations on how to conduct a workshop. Chapter 6: Event Storming - This chapter introduces the reader to the event storming workshop format and discusses how to set one up. It explains in detail the steps of an event storming workshop, from finding and consolidating the events to assigning aggregates and reading models. Chapter 7: Context Map - This chapter introduces the context map as a tool for discussing
Page
9
viii ■ context map and discuss synchronous and asynchronous interfaces. It also shows the API definitions and how to add interfaces to the context map. Chapter 8: Overview of Strategic Design - This chapter gives an overview of the strategic part of Domain-Driven Design. It discusses the importance of strategic design and the relationship between design and team dependencies. The chapter also offers tips and tricks for applying strategic design in daily work. Chapter 9: Introduction to Tactical Design - This chapter gives a first overview of the tactical part of the design. It discusses the role of a model in software development and explains how to evolve the ubiquitous language. It also provides an overview of the tactical pattern of Domain-Driven Design. Chapter 10: Aggregate, Entity, and Value Object - This chapter discusses the topic in detail and provides a model of the online library. It also provides and discusses the patterns repository, orchestrator, and factories. Chapter 11: Exposing Aggregates via APIs - This chapter discusses the necessary synchronous APIs of a bounded context and how to define them. It also discusses the properties of a RESTful API and its specification. The theory is applied in practice using the online library as an example. Chapter 12: Exposing Domain Events - This chapter discusses how to expose the domain events of a bounded context. The events are defined using AsyncAPI. The events of the online library are used as an example. Furthermore, the definition of services is discussed for the events. Chapter 13: Pitfalls in Tactical Design - This chapter discusses the dependencies between team responsibilities and tactical design. It points to pitfalls and gives hints on how to avoid them. Chapter 14: Usage of Domain-Driven Design in a Greenfield - This chapter gives a comprehensive overview of the process using the example of a bike rental shop. It offers hints on how to set up the workshops and find the right audience. Using the example, it describes how to document the workshop results and the architectural decisions. Furthermore, the chapter describes how to evolve a DDD process. Chapter 15: Domain-Driven Design in a Brownfield Project - This chapter discusses the process in a brownfield project using the example of a classic community library. It describes prioritizing the capabilities and applying a step-by-step approach to the necessary modernization. It emphasizes again the required organizational changes.tic Chapter 16: Summary - This chapter summarizes the content of the previous chapters and comprehensively describes the synergetic blueprint process. It gives an overview of strategic and tactical design and how to apply the method to projects. It also discusses the
Page
10
■ ix Coloured Images Please follow the link to download the Coloured Images of the book: https://rebrand.ly/14c67c We have code bundles from our rich catalogue of books and videos available at https://github.com/bpbpublications. Check them out! Errata We take immense pride in our work at BPB Publications and follow best practices to ensure the accuracy of our content to provide with an indulging reading experience to our subscribers. Our readers are our mirrors, and we use their inputs to reflect and improve upon human errors, if any, that may have occurred during the publishing processes involved. To let us maintain the quality and help us reach out to any readers who might be having difficulties due to any unforeseen errors, please write to us at : errata@bpbonline.com Your support, suggestions and feedbacks are highly appreciated by the BPB Publications’ Family. Did you know that BPB offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.bpbonline. com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at : business@bpbonline.com for more details. At www.bpbonline.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on BPB books and eBooks.
Page
11
x ■ Piracy If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at business@bpbonline.com with a link to the material. If you are interested in becoming an author If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit www.bpbonline.com. We have worked with thousands of developers and tech professionals, just like you, to help them share their insights with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea. Reviews Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions. We at BPB can understand what you think about our products, and our authors can see your feedback on their book. Thank you! For more information about BPB, please visit www.bpbonline.com. Join our book's Discord space Join the book's Discord Workspace for Latest updates, Offers, Tech happenings around the world, New Release and Sessions with the Authors: https://discord.bpbonline.com
Page
12
■ xi Table of Contents 1. Introduction to Domain-Driven Design........................................................................ 1 Introduction................................................................................................................. 1 Structure...................................................................................................................... 1 Objectives ................................................................................................................... 1 Short history of Domain-Driven Design ................................................................... 2 Publication of the blue book ..................................................................................... 2 Domain models and their shortcomings ................................................................... 2 Microservices require a shift.................................................................................... 3 Complexity of modern software systems ................................................................. 5 Handling complexity .............................................................................................. 5 Software complexity in a VUCA world ................................................................... 7 Tackling complexity ................................................................................................... 9 Design Thinking..................................................................................................... 9 Complexity and analysis ....................................................................................... 10 CAP theorem ........................................................................................................ 14 Commensurate complexity .................................................................................... 15 Software architecture ............................................................................................. 17 Conclusion ................................................................................................................. 19 Points to remember .................................................................................................. 19 Multiple choice questions ........................................................................................ 20 Answers ................................................................................................................ 20 2. Introduction to the Example Online Library ............................................................. 21 Introduction............................................................................................................... 21 Structure.................................................................................................................... 21 Objectives .................................................................................................................. 21 First ideas................................................................................................................... 22 Business plan model ................................................................................................ 26 Capability map ......................................................................................................... 27
Page
13
xii ■ Conclusion ................................................................................................................. 34 Points to remember .................................................................................................. 34 Multiple choice questions ........................................................................................ 34 Answers ................................................................................................................ 35 3. Why Strategic Design ................................................................................................... 37 Introduction............................................................................................................... 37 Structure.................................................................................................................... 37 Objectives .................................................................................................................. 38 Influence of software architecture in a system ....................................................... 38 Team independence ................................................................................................. 39 Conway’s Law .......................................................................................................... 41 Better software .......................................................................................................... 42 Software quality ................................................................................................... 42 Security ................................................................................................................ 44 Software quality aspects and DDD ........................................................................ 45 Conclusion ................................................................................................................. 46 Points to remember .................................................................................................. 46 Multiple choice questions ........................................................................................ 47 Answers ................................................................................................................ 48 4. Bounded Context and Domain .................................................................................... 49 Introduction............................................................................................................... 49 Structure.................................................................................................................... 49 Objectives .................................................................................................................. 49 Domains .................................................................................................................... 50 Subdomains ............................................................................................................... 51 Wardley Mapping ................................................................................................ 52 Purpose .............................................................................................................................. 52 Scope .................................................................................................................................. 52 Users ................................................................................................................................. 53 User needs ........................................................................................................................ 53 Value chain ....................................................................................................................... 54
Page
14
■ xiii Final step in mapping ..................................................................................................... 56 Distilling core, supportive, and generic domains .................................................. 59 Bounded context and aggregate.............................................................................. 63 Patterns in strategic design ...................................................................................... 64 Shared Kernel ....................................................................................................... 64 Conformist ............................................................................................................ 66 Anti-Corruption Layer .......................................................................................... 67 Open Host Service ................................................................................................ 68 Conclusion ................................................................................................................. 69 Points to remember .................................................................................................. 69 Multiple choice questions ........................................................................................ 70 Answers ................................................................................................................ 72 5. Domain Storytelling ..................................................................................................... 73 Introduction............................................................................................................... 73 Structure.................................................................................................................... 73 Objectives .................................................................................................................. 73 Target of domain storytelling .................................................................................. 74 Storytelling ........................................................................................................... 75 Visual language of domain storytelling ................................................................. 81 Workshop setup ........................................................................................................ 83 Workshop attendees .............................................................................................. 83 Whiteboards .......................................................................................................... 84 Modeling tools ...................................................................................................... 84 Workshop length ................................................................................................... 86 Enhancing domain storytelling for existing systems ............................................. 87 Domain storytelling of the online library ............................................................... 88 Purchase of books .................................................................................................. 88 Membership management ..................................................................................... 89 Reading ................................................................................................................. 90 Discussion ............................................................................................................ 91 Recommendations ................................................................................................. 92 Visual glossary .......................................................................................................... 93
Page
15
xiv ■ Recommendations for a domain storytelling workshop ....................................... 96 Conclusion ................................................................................................................. 97 Points to remember .................................................................................................. 98 Multiple choice questions ........................................................................................ 99 Answers .............................................................................................................. 100 6. Event Storming ............................................................................................................ 101 Introduction............................................................................................................. 101 Structure.................................................................................................................. 101 Objectives ................................................................................................................ 102 Target of an event storming workshop ................................................................. 102 Brainstorming .................................................................................................... 102 Event storming ................................................................................................... 103 Setup of the workshop............................................................................................ 103 Scheduling .......................................................................................................... 104 Tooling ................................................................................................................ 104 Event storming in detail ......................................................................................... 105 Collection of events ................................................................................................ 106 Consolidation of events .......................................................................................... 107 Finding the commands ........................................................................................... 109 Roles and processes................................................................................................ 110 Finding aggregates and views ................................................................................ 111 Finding bounded contexts ..................................................................................... 112 Event storming of the online library ..................................................................... 113 Purchase ............................................................................................................. 114 Member management .......................................................................................... 115 Membership calculation ...................................................................................... 118 Visual glossary enhancement ....................................................................................... 118 Reading ............................................................................................................... 120 Visual glossary enhancement ....................................................................................... 124 Discussions ......................................................................................................... 125 Vi sual glossary enhancement ................................................................................... 126 Recommendation ................................................................................................ 127
Page
16
■ xv Bounded context canvas ......................................................................................... 128 Guidelines in event storming workshops ............................................................. 130 Conclusion ............................................................................................................... 132 Points to remember ................................................................................................ 133 Multiple choice questions ...................................................................................... 133 Answers .............................................................................................................. 134 7. Context Map ................................................................................................................. 135 Introduction............................................................................................................. 135 Structure.................................................................................................................. 135 Objectives ................................................................................................................ 136 Context map ............................................................................................................ 136 Creation of a context map ...................................................................................... 139 Domain events and REST interfaces...................................................................... 140 Synchronous communication .............................................................................. 141 Asynchronous communication ............................................................................ 141 West-east and north-south communication ......................................................... 142 Applying communication patterns in context map .............................................. 143 API definitions ........................................................................................................ 143 Purchase ............................................................................................................. 144 Member management .......................................................................................... 144 Reading ............................................................................................................... 146 Discussions ......................................................................................................... 148 Context map and API definition ........................................................................... 150 Conclusion ............................................................................................................... 152 Points to remember ................................................................................................ 152 Multiple choice questions ...................................................................................... 153 Answers .............................................................................................................. 154 8. Overview of Strategic Design.................................................................................... 155 Introduction............................................................................................................. 155 Structure.................................................................................................................. 155 Objectives ................................................................................................................ 155
Page
17
xvi ■ Overview of strategic design ................................................................................. 156 Significance of strategic design ............................................................................. 160 Development over the years ................................................................................ 160 Development and purchase ................................................................................. 161 Define the structure of development......................................................................161 Relationship of bounded context and team structure .......................................... 162 Open host service ............................................................................................... 162 Anti-corruption layer .......................................................................................... 162 Conformist .......................................................................................................... 163 Big Ball of Mud .................................................................................................. 163 Tips and tricks for applying strategic design ....................................................... 164 Definition of business capabilities.........................................................................164 Training for the teams..........................................................................................164 API-first strategy ............................................................................................... 164 Governance process ............................................................................................. 165 Team structure .................................................................................................... 167 Conclusion ............................................................................................................... 167 Points to remember ................................................................................................ 168 Multiple choice questions ...................................................................................... 168 Answers .............................................................................................................. 169 9. Introduction to Tactical Design ................................................................................. 171 Introduction............................................................................................................. 171 Structure.................................................................................................................. 171 Objectives ................................................................................................................ 172 Tactical design ......................................................................................................... 172 Tactical design for modeling.................................................................................. 172 Model-driven design.............................................................................................. 173 Further development of the ubiquitous language................................................ 177 Patterns provided by DDD .................................................................................... 179 Conclusion ............................................................................................................... 180 Points to remember ................................................................................................ 180 Multiple choice questions ...................................................................................... 180
Page
18
■ xvii Answers .............................................................................................................. 181 10. Aggregate, Entity, and Value Object......................................................................... 183 Introduction............................................................................................................. 183 Structure.................................................................................................................. 183 Objectives ................................................................................................................ 184 Aggregate, entity, and value object ....................................................................... 184 Aggregates .......................................................................................................... 184 Entity................................................................................................................. 186 Value object ........................................................................................................ 187 Example model of the online library ..................................................................... 187 Repository ............................................................................................................... 193 Factories and orchestrators .................................................................................... 194 Factories ............................................................................................................. 195 Orchestrator ....................................................................................................... 196 Choreography ..................................................................................................... 197 Conclusion ............................................................................................................... 200 Points to remember ................................................................................................ 200 Multiple choice questions ...................................................................................... 201 Answers .............................................................................................................. 201 11. Exposing Aggregates via APIs ................................................................................... 203 Introduction............................................................................................................. 203 Structure.................................................................................................................. 203 Objectives ................................................................................................................ 203 Introduction to RESTful APIs and its specification .............................................. 204 Application programming interface ..................................................................... 204 REST ................................................................................................................. 204 OpenAPI specification language for RESTful APIs..............................................206 Specification of the API of task management ....................................................... 208 Schema design..................................................................................................... 208 Resource paths .................................................................................................... 211 Tasks Get ........................................................................................................................ 211
Page
19
xviii ■ Tasks Post ....................................................................................................................... 212 Single task Get ............................................................................................................... 213 Single task Delete .......................................................................................................... 213 APIs for online library ............................................................................................ 214 API of Catalog Management ............................................................................... 215 API Member Management .................................................................................. 215 API of discussions .............................................................................................. 218 Notes API ........................................................................................................... 224 Conclusion ............................................................................................................... 227 Points to remember ............................................................................................... 227 Multiple choice questions ...................................................................................... 228 Answers .............................................................................................................. 229 12. Exposing Domain Events........................................................................................... 231 Introduction............................................................................................................. 231 Structure.................................................................................................................. 231 Objectives ................................................................................................................ 231 Introduction to event-driven architecture ............................................................ 232 Broker architecture ................................................................................................. 233 Event-streaming ................................................................................................. 234 Publish and subscribe .......................................................................................... 235 Defining events using AsyncAPI .......................................................................... 235 Structure of an AsyncAPI ................................................................................... 236 Skeleton of an AsyncAPI specification..................................................................237 Pure message definitions of the library.................................................................239 Header of the messages...................................................................................................239 Book purchased ............................................................................................................... 240 Catalog entry created, catalog entry updated ............................................................. 241 Book lent, book returned ................................................................................................ 242 Member created .............................................................................................................. 243 Amount paid .................................................................................................................. 243 Reading position marked ............................................................................................... 245 Definitions of the services ...................................................................................... 245
Page
20
■ xix Conclusion ............................................................................................................... 246 Points to remember ................................................................................................ 246 Multiple choice questions ...................................................................................... 247 Answers .............................................................................................................. 248 Bibliography ............................................................................................................ 248 13. Pitfalls in Tactical Design .......................................................................................... 249 Introduction............................................................................................................. 249 Structure.................................................................................................................. 249 Objectives ................................................................................................................ 249 Team responsibility and tactical design ................................................................ 250 Check implementation consistency by LLMs ....................................................... 250 Ubiquitous language ........................................................................................... 253 Pitfalls and how to avoid them ............................................................................. 254 Driven by database design .................................................................................. 254 Purely out of the provider’s point of view ............................................................ 254 Purely technical solutions ................................................................................... 255 Trying to solve someone else’s problem ................................................................ 255 Conclusion ............................................................................................................... 256 Points to remember ................................................................................................ 256 Multiple choice questions ...................................................................................... 257 Answers .............................................................................................................. 257 14. Usage of Domain-Driven Design in a Greenfield .................................................. 259 Introduction............................................................................................................. 259 Structure.................................................................................................................. 259 Objectives ................................................................................................................ 260 Setting up a workshop ............................................................................................ 263 Capability map and Wardley Map ....................................................................... 264 Domain storytelling and event storming ............................................................. 266 Context map ....................................................................................................... 271 API design .......................................................................................................... 272 Finding target audience for the workshops ......................................................... 273