100% found this document useful (14 votes)
82 views

Download Exploring CQRS and Event Sourcing A journey into high scalability availability and maintainability with Windows Azure 1st Edition Dominic Betts ebook All Chapters PDF

Dominic

Uploaded by

marshwyldez0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (14 votes)
82 views

Download Exploring CQRS and Event Sourcing A journey into high scalability availability and maintainability with Windows Azure 1st Edition Dominic Betts ebook All Chapters PDF

Dominic

Uploaded by

marshwyldez0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Download the full version of the ebook at ebookname.

com

Exploring CQRS and Event Sourcing A journey into


high scalability availability and maintainability
with Windows Azure 1st Edition Dominic Betts

https://ebookname.com/product/exploring-cqrs-and-event-
sourcing-a-journey-into-high-scalability-availability-and-
maintainability-with-windows-azure-1st-edition-dominic-
betts/

OR CLICK BUTTON

DOWNLOAD EBOOK

Download more ebook instantly today at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Mastering Hyper V 2012 R2 with System Center and Windows


Azure 1st Edition John Savill

https://ebookname.com/product/mastering-hyper-v-2012-r2-with-system-
center-and-windows-azure-1st-edition-john-savill/

ebookname.com

Windows Azure Web Sites 1st Edition James Chambers

https://ebookname.com/product/windows-azure-web-sites-1st-edition-
james-chambers/

ebookname.com

Windows Azure Hybrid Cloud 1st Edition Danny Garber

https://ebookname.com/product/windows-azure-hybrid-cloud-1st-edition-
danny-garber/

ebookname.com

A Manual of Egyptian Pottery Fayum A Lower Egytpian


Culture 1, revised Edition Anna Wodzinska

https://ebookname.com/product/a-manual-of-egyptian-pottery-fayum-a-
lower-egytpian-culture-1-revised-edition-anna-wodzinska/

ebookname.com
Researcher Race Social Constructions in the Research
Process 1st Edition Lauren Mizock

https://ebookname.com/product/researcher-race-social-constructions-in-
the-research-process-1st-edition-lauren-mizock/

ebookname.com

OCP Java SE 7 Programmer II Certification Guide Prepare


for the 1ZO 804 exam 1st Edition Mala Gupta

https://ebookname.com/product/ocp-java-se-7-programmer-ii-
certification-guide-prepare-for-the-1zo-804-exam-1st-edition-mala-
gupta/
ebookname.com

Intelligence Theory Key Questions and Debates Studies in


Intelligence 1st Edition Mark Phythian:

https://ebookname.com/product/intelligence-theory-key-questions-and-
debates-studies-in-intelligence-1st-edition-mark-phythian/

ebookname.com

Contemporary Mathematics for Business and Consumers 5th


Edition with Student Resource CD with MathCue Business
Robert Brechner
https://ebookname.com/product/contemporary-mathematics-for-business-
and-consumers-5th-edition-with-student-resource-cd-with-mathcue-
business-robert-brechner/
ebookname.com

Carrots and Related Apiaceae Crops 2nd Edition Emmanuel


Geoffriau

https://ebookname.com/product/carrots-and-related-apiaceae-crops-2nd-
edition-emmanuel-geoffriau/

ebookname.com
Cambridge Young Learners English Tests 7 Starters Student
s Book Examination Papers from University of Cambridge
ESOL Examinations 1st Edition Cambridge Esol
https://ebookname.com/product/cambridge-young-learners-english-
tests-7-starters-student-s-book-examination-papers-from-university-of-
cambridge-esol-examinations-1st-edition-cambridge-esol/
ebookname.com
Exploring CQRS and
Event Sourcing
A journey into high scalability, availability,
and maintainability with Windows Azure
Exploring CQRS and
Event Sourcing
A journey into high scalability, availability,
and maintainability with Windows Azure

Dominic Betts
Julián Domínguez
Grigori Melnik
Fernando Simonazzi
Mani Subramanian
978-1-62114-016-0
This document is provided “as-is”. Information and views expressed in
this document, including URL and other Internet Web site references,
may change without notice.
Some examples depicted herein are provided for illustration only and are
fictitious. No real association or connection is intended or should be
inferred.
This document does not provide you with any legal rights to any
intellectual property in any Microsoft product. You may copy and use
this document for your internal, reference purposes. You may modify this
document for your internal, reference purposes
© 2012 Microsoft. All rights reserved.
Microsoft, MSDN, SQL Azure, SQL Server, Visual Studio, Windows, and
Windows Azure are trademarks of the Microsoft group of companies. All
other trademarks are property of their respective owners.
Contents

What other readers are saying about this guide xvii


Foreword by Greg Young xxi
Preface xxiii
Why we created this guidance now xxiii
How is this guidance structured? xxiii
A CQRS journey xxiv
CQRS reference xxv
Tales from the trenches xxv
A CQRS journey xxv
CQRS reference xxvi
Tales from the trenches xxvi
Selecting the domain for the RI xxvi
Arrow legend xxvii
Where to go for more information xxviii

The Crew xxix


Journey 1: Our Domain: Conference Management System 1
The Contoso Corporation 1
Who is coming with us on the journey? 2
The Contoso Conference Management System 3
Overview of the system 3
Selling seats for a conference 4
Creating a conference 4
Nonfunctional requirements 4
Scalability 4
Flexibility 5
Beginning the journey 5
More information 5

v
vi

Journey 2: Decomposing the Domain 7


Definitions used in this chapter 7
Bounded contexts in the conference management system 8
Bounded contexts not included 9
The context map for the Contoso Conference Management
System 10
Why did we choose these bounded contexts? 11
More information 11

Journey 3: Orders and Registrations Bounded Context 13


A description of the bounded context 13
Working definitions for this chapter 14
Domain definitions (ubiquitous language) 15
Requirements for creating orders 17
Architecture 18
Patterns and concepts 18
Validation 23
Transaction boundaries 24
Concurrency 25
Aggregates and aggregate roots 25
Implementation details 25
High-level architecture 26
1. Querying the read model 27
2. Issuing commands 28
3. Handling commands 28
4. Initiating business logic in the domain 29
5. Persisting the changes 29
6. Polling the read model 29
Inside the write model 31
Aggregates 31
Aggregates and process managers 34
Infrastructure 40
Using the Windows Azure Service Bus 42
Delivering a command to a single recipient 44
Why have separate CommandBus and EventBus
classes? 48
How scalable is this approach? 48
How robust is this approach? 48
What is the granularity of a topic and a subscription? 48
How are commands and events serialized? 49
Impact on testing 49
Summary 52
More information 52
vii

Journey 4: Extending and Enhancing the Orders and


Registrations Bounded Context 53
Changes to the bounded context 53
Working definitions for this chapter 53
User stories 54
Implement a login using a record locator 54
Tell the registrant how much time remains to complete
an order 55
Enable a registrant to create an order that includes
multiple seat types 55
Architecture 55
Patterns and concepts 56
Record locators 56
Querying the read side 56
Storing denormalized views in a database 57
Making information about partially fulfilled orders
available to the read side 60
CQRS command validation 61
The countdown timer and the read model 62
Implementation details 62
The order access code record locator 63
The countdown timer 64
Using ASP.NET MVC validation for commands 66
Pushing changes to the read side 69
Querying the read side 72
Refactoring the SeatsAvailability aggregate 73
The AddSeats method 74
Impact on testing 74
Acceptance tests and the domain expert 74
Defining acceptance tests using SpecFlow features 74
Making the tests executable 76
Using tests to help developers understand message flows 81
A journey into code comprehension: A tale of pain, relief,
and learning 83
Testing is important 83
Domain tests 84
The other side of the coin 86
Summary 90
More information 90

Journey 5: Preparing for the V1 Release 91


The Contoso Conference Management System V1 release 91
Working definitions for this chapter 91
User stories 92
Ubiquitous language definitions 92
Conference Management bounded context user stories 92
Ordering and Registration bounded context user stories 92
viii

Architecture 93
Conference Management bounded context 97
Patterns and concepts 97
Event sourcing 97
Identifying aggregates 98
Task-based UI 99
CRUD 101
Integration between bounded contexts 101
Pushing changes from the Conference Management
bounded context 102
Pushing changes to the Conference Management
bounded context 104
Choosing when to update the read-side data 105
Distributed transactions and event sourcing 105
Autonomy versus authority 105
Favoring autonomy 106
Favoring authority 106
Choosing between autonomy and authority 106
Approaches to implementing the read side 107
Eventual consistency 107
Implementation details 108
The Conference Management bounded context 108
Integration with the Orders and Registration bounded
context 108
The Payments bounded context 109
Integration with online payment services, eventual
consistency, and command validation 111
Event sourcing 113
Raising events when the state of an aggregate changes 113
Persisting events to the event store 117
Replaying events to rebuild state 118
Issues with the simple event store implementation 120
Windows Azure table storage-based event store 120
Calculating totals 122
Impact on testing 123
Timing issues 123
Involving the domain expert 123
Summary 124
More information 124

Journey 6: Versioning Our System 125


Working definitions for this chapter 125
User stories 126
No down time upgrade 126
Display remaining seat quantities 126
Handle zero-cost seats 126
Architecture 126
ix

Patterns and concepts 127


Handling changes to events definitions 128
Mapping/filtering event messages in the infrastructure 128
Handling multiple message versions in the aggregates 128
Honoring message idempotency 128
Avoid processing events multiple times 129
Persisting integration events 131
Message ordering 133
Implementation details 133
Adding support for zero-cost orders 134
Changes to the RegistrationProcessManager class 134
Changes to the UI 134
Data migration 136
Displaying remaining seats in the UI 138
Adding information about remaining seat quantities
to the read model 138
Modifying the UI to display remaining seat quantities 140
Data migration 140
De-duplicating command messages 141
Guaranteeing message ordering 142
Persisting events from the Conference Management
bounded context 146
Adding additional metadata to the messages 146
Capturing and persisting messages to the message log 146
Data migration 148
Migrating from V1 to V2 150
Generating past log messages for the Conference
Management bounded context 151
Migrating the event sourcing events 151
Rebuilding the read models 151
Impact on testing 151
SpecFlow revisited 152
Discovering a bug during the migration 155
Summary 155
More information 155

Journey 7: Adding Resilience and Optimizing Performance 157


Working definitions for this chapter 157
Architecture 158
Adding resilience 159
Making the system resilient when an event is reprocessed 161
Ensuring that commands are always sent 161
Optimizing performance 162
UI flow before optimization 162
Optimizing the UI 163
UI optimization 1 164
UI optimization 2 165
x

Optimizing the infrastructure 165


Sending and receiving commands and events
asynchronously 165
Optimizing command processing 166
Using snapshots with event sourcing 166
Publishing events in parallel 167
Filtering messages in subscriptions 167
Creating a dedicated receiver for the SeatsAvailability
aggregate 167
Caching conference information 167
Partitioning the Service Bus 168
Other optimizations 168
Further changes that would improve performance 169
Further changes that would enhance scalability 171
No down-time migration 172
Rebuilding the read models 173
Implementation details 174
Hardening the RegistrationProcessManager class 174
Detecting out-of-order SeatsReserved events 175
Detecting duplicate OrderPlaced events 178
Creating a pseudo transaction when the
RegistrationProcessManager class saves its state
and sends a command 178
Optimizing the UI flow 181
Receiving, completing, and sending messages
asynchronously 186
Receiving messages asynchronously 186
Completing messages asynchronously 186
Sending messages asynchronously 186
Handling commands synchronously and in-process 186
Implementing snapshots with the memento pattern 189
Publishing events in parallel 191
Filtering messages in subscriptions 192
Creating a dedicated SessionSubscriptionReceiver
instance for the SeatsAvailability aggregate 193
Caching read-model data 194
Using multiple topics to partition the service bus 195
Other optimizing and hardening changes 196
Sequential GUIDs 196
Asynchronous ASP.NET MVC controllers. 198
Using prefetch with Windows Azure Service Bus 198
Accepting multiple sessions in parallel 199
Adding an optimistic concurrency check 199
Adding a time-to-live value to the
MakeSeatReservation command 199
Reducing the number of round-trips to the database 199
xi

Impact on testing 200


Integration tests 200
User interface tests 200
Summary 200
More information 200

Journey 8: Epilogue: Lessons Learned 201


What did we learn? 201
Performance matters 201
Implementing a message-driven system is far from simple 202
The cloud has challenges 203
CQRS is different 204
Event sourcing and transaction logging 205
Involving the domain expert 206
When to use CQRS 206
What would we do differently if we started over? 207
Start with a solid infrastructure for messaging and
persistence 207
Leverage the capabilities of the infrastructure more 207
Adopt a more systematic approach to implementing
process managers 208
Partition the application differently 208
Organize the development team differently 208
Evaluate how appropriate the domain and the bounded
contexts are for the CQRS pattern 208
Plan for performance 208
Think about the UI differently 209
Explore some additional benefits of event sourcing 209
Explore the issues associated with integrating bounded
contexts 210
More information 210
Reference 1: CQRS in Context 211
What is domain-driven design? 212
Domain-driven design: concepts and terminology 212
Domain model 213
Ubiquitous language 213
Entities, value objects, and services 214
Aggregates and aggregate roots 215
Bounded contexts 215
Anti-corruption layers 217
Context maps 218
Bounded contexts and multiple architectures 218
Bounded contexts and multiple development teams 219
Maintaining multiple bounded contexts 220
CQRS and DDD 220
More information 221
xii

Reference 2: Introducing the Command Query


Responsibility Segregation Pattern 223
What is CQRS? 223
Read and write sides 225
CQRS and domain-driven design 227
Introducing commands, events, and messages 228
Why should I use CQRS? 230
Scalability 230
Reduced complexity 231
Flexibility 231
Focus on the business 232
Facilitates building task-based UIs 232
Barriers to adopting the CQRS pattern 232
When should I use CQRS? 232
Collaborative domains 233
Stale data 233
Moving to the cloud 234
When should I avoid CQRS? 234
Summary 234
More information 234

Reference 3: Introducing Event Sourcing 235


What is event sourcing? 236
Comparing using an ORM layer with event sourcing 236
Why should I use event sourcing? 240
Event sourcing concerns 242
CQRS/ES 243
Standalone event sourcing 245
Event stores 245
Basic requirements 245
Underlying storage 245
Performance, scalability, and consistency 245
More information 246

Reference 4: A CQRS and ES Deep Dive 247


Introduction 247
Read models and write models 247
Commands and data transfer objects 247
Domain-driven design (DDD) and aggregates 248
Data and normalization 248
Events and event sourcing 248
Eventual consistency 248
Defining aggregates in the domain model 249
Aggregates and object-relational mapping layers 249
Aggregates and event sourcing 250
xiii

Commands and command handlers 252


Commands 253
Example code 253
Command handlers 254
Commands and optimistic concurrency 256
Events and event handlers 256
Events and intent 256
How to model intent 258
Events 259
Sample Code 259
Event handlers 260
Sample code 260
Embracing eventual consistency 261
Eventual consistency and CQRS 263
Optimizing the read-side 266
Optimizing the write side 267
Concurrency and aggregates 267
Messaging and CQRS 268
Messaging considerations 268
Duplicate messages 268
Lost messages 269
Out-of-order messages 269
Unprocessed messages 269
Event versioning 269
Redundant events 270
New event types 270
Changing existing event definitions 270
Task-based UIs 271
Taking advantage of Windows Azure 272
Scaling out using multiple role instances 273
Implementing an event store using Windows Azure
table storage 273
Persisting events 274
Retrieving events 275
Publishing events 276
Implementing a messaging infrastructure using
the Windows Azure Service Bus 278
A word of warning 279
More information 279

Reference 5: Communicating Between Bounded Contexts 281


Introduction 281
Context maps 281
The anti-corruption layer 281
xiv

Integration with legacy systems 282


Reading the database 282
Generating events from the database 282
Modifying the legacy systems 282
Implications for event sourcing 282
More information 283

Reference 6: A Saga on Sagas 285


Clarifying the terminology 285
Process Manager 286
Messages and CQRS 286
What is a process manager? 286
When should I use a process manager? 290
When should I not use a process manager? 290
Sagas and CQRS 290
More information 290

Reference 7: Technologies Used in the Reference


Implementation 291
Windows Azure Service Bus 291
Queues 292
Topics and Subscriptions 293
Useful API features 294
Reading messages 294
Sending messages 294
Expiring messages 294
Delayed message processing 294
Serializing messages 295
Further information 295
Unity Application Block 296
Further information 296
More information 296

Tales from the Trenches 297


Twilio 297
Product overview 297
Lessons learned 297
Separating reads and writes 297
Designing for high availability 297
Idempotency 298
No-downtime deployments 298
Performance 298
References 299
More information 299
xv

Tales from the Trenches: Lokad Hub 300


Project overview 300
Lessons learned 300
Benefits of DDD 301
Reducing dependencies 301
Using sagas 301
Testing and documentation 301
Migration to ES 301
Using projections 301
Event sourcing 301
Infrastructure 302
References 302
More information 302

Tales from the Trenches: DDD/CQRS for large financial


company 303
Project overview 303
Lessons learned 304
Query performance 304
Commands 304
Working with legacy databases 304
Using an Inversion of Control (IoC) container 304
Key lessons learned 305
More information 305

Tales from the Trenches: Digital Marketing 306


Single Responsibility of Objects 309
More information 309

Tales from the Trenches: TOPAZ Technologies 310


What did we hope to accomplish by using CQRS/ES? 310
What were the biggest challenges and how did we
overcome them? 310
What were the most important lessons learned? 311
With hindsight, what would we have done differently? 311
Further information 311
More information 311

Tales from the Trenches: eMoney Nexus 312


eMoney Nexus: Some CQRS lessons 312
About eMoney & the Nexus 312
System overview 313
The evolution of the system 314
Lessons learned 320
Making it better 321
xvi

Appendix 1: Release Notes 323


System evolution 323
Building and running the sample code (RI) 323
Prerequisites 324
Obtaining the code 325
Creating the databases 325
SQL Express Database 325
Windows Azure SQL Database instance 325
Creating the Settings.xml File 327
Building the RI 327
Build Configurations 328
Release 328
Debug 328
DebugLocal 328
Running the RI 328
Scenario 1. Local Web Server, SQL Event Bus,
SQL Event Store 328
Scenario 2. Local Web Server, Windows Azure
Service Bus, Table Storage Event Store 329
Scenario 3. Compute Emulator, SQL Event Bus,
SQL Event Store 329
Scenario 4. Compute Emulator, Windows Azure
Service Bus, Table Storage Event Store 329
Scenario 5. Windows Azure, Windows Azure
Service Bus, Table Storage Event Store 329
Running the Tests 329
Running the Unit and Integration Tests 329
Running the Acceptance Tests 330
Known issues 330
More information 330

Appendix 2: Migrations 331


Migrating from the V1 to the V2 release 331
Running the migration program to migrate the data 331
If the data migration fails 332
Migrating from the V2 to the V3 Release 333
More information 333

Index 335
What other readers are
saying about this guide

This is another excellent guide from the patterns & practices team—real software engineering with
no comforting illusions taken or offered. This guide provides a detailed journal of the practitioners
implementing a real production system using the CQRS and Event Sourcing patterns, and also high-
lights the tradeoffs and teaches the principles that underlie them. The topics presented are relevant
and useful, especially if you are building highly scalable Windows Azure applications. You’ll be both
challenged and inspired!
—Scott Guthrie, Corporate Vice-President, Azure App Platform, Microsoft

Having participated and co-authored various guides from patterns & practices, the “CQRS Journey”
follows the same walkthrough, scenario-based style, but adding even more fresh empirical content.
It’s a true testament of a skilled development team without previous CQRS experience, going through
the journey of implementing a complex system and documenting their adventures and lessons learnt
in this diary. If I had to recommend to someone where to start with CQRS, I would definitely point
them to this guide.
—Matias Woloski, CTO, Auth10 LLC

The “CQRS Journey” guide is an excellent resource for developers who want to begin developing a
CQRS system or convert their current system. It’s a true “trial by fire” approach to the concepts and
implementation hurdles that a team would encounter when adopting CQRS. I would recommend
reading it twice as I picked up even more lessons the second time through.
—Dan Piessens, Lead Software Architect, Zywave

I think it’s a really big step in communication with the developer community. You not only share your
development experience with a broad audience (which is very valuable by itself) but you’re also open
for learning from the community. While working on real projects it’s difficult to stop, find some time
to structure your knowledge, prepare it in the form understandable for others. It’s very cool that you
found time and resources for such educational effort, I really appreciate this.
—Ksenia Mukhortova, Business Applications Developer, Intel

I’m very excited about A CQRS Journey for a number of reasons. It explores, with an even hand and a
fair mind, a topic where opinions are both diverse and numerous. True to its name, the guide captures
the progression of learning. Conclusions are not simply stated; they arrive as a result of experience.
Additionally, the project embraced a passionate community with a spirit of inclusion and transparency.
The result is friendly-to-read guidance that is both diligent in execution and rigorous in its research.
—Christopher Bennage, Software Development Engineer, Microsoft

xvii
xviii

The journey project used Windows Azure SQL Database (backing write & read models), Service Bus
(for reliable messaging), and Tables (for event store). Production-quality, scalable cloud services that
can be provisioned on-demand with a few mouse-clicks (or API calls) can turn some tough infrastruc-
ture problems into trivial ones.
—Bill Wilder, MVP, Independent Consultant

Perhaps the best lessons out of this guidance will be just how easy it is to work with Microsoft now
that they are embracing more community and open source.
—Adam Dymitruk, Systems Architect

The work that patterns & practices is doing here is very important as it is packaging the concepts in
a digestible fashion and helping developers to wade through the ambiguities of CQRS. The real world
experiences captured within the journey project will be invaluable to folks looking at applying CQRS
within their application development”
—Glenn Block, Senior Program Manager, Microsoft, Windows Azure SDK for Node.js,
Organizer at ALT.NET Seattle Chapter

The p&p team’s dedication and hard work go hand-in-hand with the very high level of competency
present on the team. Their attention to detail, insistence on clarity, and open collaboration with the
community all led to the creation of material representing enormous value to consumers of the guid-
ance. I definitely plan on referencing this material and code in future engagements because I think my
clients will derive many benefits from it–a win-win for everyone!
—Josh Elster, Principal, Liquid Electron

CQRS is a very important pattern, and a tool that any cloud developer should have in his or her tool-
belt. It is particularly well-suited for the cloud since it allows for the implementation of massively
scalable solutions based on simple, common patterns (like queues, event handlers, and view models,
to name a few). Like all patterns, there are several concrete, correct ways of implementing CQRS. A
journey of the type undertaken by Microsoft’s patterns & practices team is a great way to explore the
different options, tradeoffs, and even possible mistakes one can make along the way, and accelerate
one’s learning of the CQRS pattern.
—Shy Cohen, Principal, Shy Cohen Consulting

patterns & practices assembled many of the active and key people in the CQRS community to join
them on the their journey with CQRS and along the way discovered confusing terminology and con-
cepts that created opportunities for leaders in the community to bring clarity to a broad audience.
The material produced is influenced from the results of building a real world application and ex-
presses the experiences from advisors and the patterns & practices team during the development
process. By request from the community to allow outside contributions, everything has been open
sourced on GitHub. Anyone interested is encouraged to take a look at the guide or implementation.
The patterns & practices team has been very welcoming to anyone who wants to collaborate on
covering additional areas, alternative implementations or further extending what is currently in place.
—Kelly Sommers, Developer
xix

Congratulations on getting to what looks to be nice guidance. I know that the announcement that
p&p was going to embark on this project caused a twitter firestorm but you seem to have come
through it well. I’m a fan of the p&p books and think you’ve done a great job in sharing good prac-
tices with the community.
—Neil Mackenzie, Windows Azure MVP

CQRS is as much about architecture community as it is about concrete patterns—thus the project is
aptly named “CQRS Journey.” The community involvement and engagement in this project is unprec-
edented for Microsoft and reflects the enthusiasm amongst the many (if may say: young) software
architects from across the industry who are rediscovering proven architecture patterns and are recom-
posing them in new ways to solve today’s challenges. For me, one takeaway from this project is that
the recipes developed here need to be carefully weighed against their alternatives. As with any soft-
ware architecture approaches that promise easy scalability or evolvability of solutions, the proof will
be in concrete, larger production implementations and how they hold up to changing needs over time.
Thus, the results of this Journey project mark a start and not a finish line.
—Clemens Vasters, Principal Technical Lead, Microsoft Corporation

The experiences and conclusions of the p&p team match up very well with our own real-world expe-
riences. Their conclusions in Chapter 8 are spot on. One of the best aspects of this guidance is that
the p&p team exposes more of their thought processes and learning throughout the Journey than
most write-ups that you may read. From arguments between Developer 1 and Developer 2 on the
team, to discussions with experts such as Greg Young and Udi Dahan, to an excellent post-project
review in Chapter 8, the thought process is out there for you to learn from.
Thanks for this great work, guys. I hope you keep this style with your upcoming guidance pieces.
—Jon Wagner, SVP & Chief Architect, eMoney Advisor

The CQRS journey release by patterns & practices provides real world insight into the increasingly
popular CQRS pattern used in distributed systems that rely upon asynchronous, message based ap-
proaches to achieve very large scale. The exploration of the issues the team faced throughout the
implementation of the pattern is extremely useful for organizations considering CQRS, both to de-
termine where the pattern is appropriate for them, and to go into the design and implementation with
a baseline understanding of the complexity it will introduce. I really enjoyed the candor around the
approach taken, the issues encountered, and the early design choices that the team would change in
hindsight. This is a must read for any organization embarking upon CQRS, regardless of what platform
they are using.
—Chris Keyser, VP Engineering, CaseNetwork

It is a great resource on tactical and technical aspects of building a distributed system.


—Rinat Abdullin, Technology Leader, Lokad

I’d like to personally thank the team for putting together such a transparent journey throughout this
project. I’m very pleased with the final release.
—Truong Nguyen, CEO, Nepsoft

It’s a good read. Lots to learn from it.


—Christian Horsdal Gammelgaard, Lead Software Architect, Mjølner Informatics
Foreword by Greg Young

I started off the new year on January 3rd with a few hour long meeting showing the team at patterns
& practices a bit about Command and Query Responsibility Segregation (CQRS) and Event Sourcing
(ES). Most of the team had previously not been exposed to these ideas. Today is almost exactly six
months later and they have produced a document of over 200 pages of discussions and guidance as
well as a full end to end example hosted in Windows Azure. This is certainly not a small feat.
When the announcement of the project came out, the twitter stream near instantly went nega-
tive as many thought that Microsoft was building a CQRS framework; which was premature from the
community. The process followed similar paths to other patterns & practices projects with a large
advisor board being set up. I believe however that the most interesting part of the process was the
decision to host the work on GitHub and allow pull requests which is an extremely open and transpar-
ent way of communicating during the project.
One of the main benefits for the community as a whole of going through such a process is that
people were forced to refine their vocabularies. There are in the DDD/CQRS/ES communities many
different voices and often times, especially in younger groups, vocabularies will go down divergent paths
leading to fractured community. An example of nebulous terminologies can be seen in the terms ”saga,”
”process manager,” and ”workflow”; the community as a whole I believe benefited from the discussions
over defining what it actually is. One of the most interesting conversations brought up for me person-
ally was defining the difference between an Event Store and a Transaction Log as legitimate arguments
can be made that either is a higher level abstraction of the other. This has led not only to many interest-
ing discussions in the community but to a far stricter future definition of what an Event Store is.
”For the things we have to learn before we can do them, we learn by doing them. ~Aristotle”
The quote above was the team motto during the project. Many will be looking towards the guidance
presented as being authoritative guidance of how things should be done. This is however not the
optimal way to look at the guidance as presented (though it does contain many bits of good authori-
tative guidance). The main benefit of the guidance is the learning experience that it contains. It is
important to remember that the team came into the ideas presented as non-experienced in CQRS
and they learned in the process of doing. This gives a unique perspective throughout much of the text
where things are learned along the way or are being seen through fresh eyes of someone recently
having learned and attempted to apply the ideas. This perspective has also brought up many interest-
ing conversations within the community. The patterns & practices team deserves credit for digging
deep, facilitating these discussions, and bringing to light various incongruities, confusions and incon-
sistencies as they went along.

xxi
xxii

Keeping in mind the origination point of the team, the most valuable bits in the text that a
reader should focus on aside from general explanations are places where tradeoffs are discussed.
There is an unfortunate tendency to seek authoritative answers that ”things should be done in this
way” when they in fact do not exist. There are many ways to proverbially skin a cat and all have their
pros and cons. The text is quite good at discussing alternative points of view that came up as possible
answers, or that received heavy discussion within the advisor group, these can often be seen in the
“developer 1/developer 2 discussions.” One such discussion I mentioned previously in defining the
difference between event sourcing and a transaction log. Many of these types of discussions come at
the end of the guidance.
How might things be approached differently? One of my favourite discussions towards the end
of the guidance dealing with performance is the independent realization that messaging is not
equivalent to distribution. This is a very hard lesson for many people to understand and the way that
it comes up rather organically and much like it would on most teams as a performance problem is a
great explanation. I can say 100 times to apply the first law of distributed computing, don’t distribute;
however seeing it from the eyes of a team dealing with a performance problem who has already made
the mistake of equating the two is a very understandable path and a great teaching tool. This section
also contains a smörgåsbord of information and insights in terms of how to build performant applica-
tions in Windows Azure.
Out in the wild, there are plenty of naïve samples of CQRS/ES implementations, which are great
for describing the concepts. There are details and challenges that will not surface till you work on a
complex, real-world production system. The value of the p&p’s sample application is that it uses a
fairly complex domain and the team went through multiple releases and focused on infrastructure
hardening, performance optimizations, dealing with transient faults and versioning, etc. — many
practical issues that you face when implementing CQRS and ES.
As with any project, people may disagree with implementation choices and decisions made. It is
important to remember the scoping of the project. The guidance is not coming from an expert view-
point throughout the process, but that of a group “learning by doing.” The process was and remains
open to contributions, and in fact this version has been reviewed, validated, and guided by experts in
the community. In the spirit of OSS “send a pull request.” This guide can serve as a valuable point to
start discussions, clear up misconceptions, and refine how we explain things, as well as drive improve-
ment both in the guidance itself and in getting consistent viewpoints throughout the community.
In conclusion I think patterns & practices has delivered to the community a valuable service in the
presentation of this guidance. The view point the guidance is written from is both an uncommon and
valuable one. It has also really been a good overall exercise for the community in terms of setting the
bar for what is being discussed and refining of the vocabularies that people speak in. Combine this
with the amount of previously difficult to find Windows Azure guidance and the guidance becomes
quite valuable to someone getting into the ideas.

Greg Young
Preface
Why are we embarking on this journey?

“The best way to observe a fish is to become a fish.”


Jacques Cousteau

Why we created this guidance now


The Command Query Responsibility Segregation (CQRS) pattern and event sourcing (ES) are cur-
rently generating a great deal of interest from developers and architects who are designing and build-
ing large-scale, distributed systems. There are conference sessions, blogs, articles, and frameworks all
dedicated to the CQRS pattern and to event sourcing, and all explaining how they can help you to
improve the maintainability, testability, scalability, and flexibility of your systems.
However, like anything new, it takes some time before a pattern, approach, or methodology is
fully understood and consistently defined by the community and has useful, practical guidance to help
you to apply or implement it.
This guidance is designed to help you get started with the CQRS pattern and event sourcing. It is
not intended to be the guide to the CQRS pattern and event sourcing, but a guide that describes the
experiences of a development team in implementing the CQRS pattern and event sourcing in a real-
world application. The development team did not work in isolation; they actively sought input from
industry experts and from a wider group of advisors to ensure that the guidance is both detailed and
practical.
The CQRS pattern and event sourcing are not mere simplistic solutions to the problems associ-
ated with large-scale, distributed systems. By providing you with both a working application and
written guidance, we expect you’ll be well prepared to embark on your own CQRS journey.

How is this guidance structured?


There are two closely related parts to this guidance:
• A working reference implementation (RI) sample, which is intended to illustrate many of the
concepts related to the CQRS pattern and event sourcing approaches to developing complex
enterprise applications.
• This written guidance, which is intended to complement the RI by describing how it works,
what decisions were made during its development, and what trade-offs were considered.

xxiii
xxiv

This written guidance is itself split into three distinct sections that you can read independently: a
description of the journey we took as we learned about CQRS, a collection of CQRS reference ma-
terials, and a collection of case studies that describe the experiences other teams have had with the
CQRS pattern. The map in Figure 1 illustrates the relationship between the first two sections: a
journey with some defined stopping points that enables us to explore a space.

Figure 1
A CQRS journey

A CQRS journey
This section is closely related to the RI and the chapters follow the chronology of the project to de-
velop the RI. Each chapter describes relevant features of the domain model, infrastructure elements,
architecture, and user interface (UI) that the team was concerned with during that phase of the
project. Some parts of the system are discussed in several chapters, and this reflects the fact that the
team revisited certain areas during later stages. Each of these chapters discuss how and why particu-
lar CQRS patterns and concepts apply to the design and development of particular bounded contexts,
describe the implementation, and highlight any implications for testing.
xxv

Other chapters look at the big picture. For example, there is a chapter that explains the rationale
for splitting the RI into the bounded contexts we chose, another chapter analyzes the implications of
our approach for versioning the system, and other chapters look at how the different bounded con-
texts in the RI communicate with each other.
This section describes our journey as we learned about CQRS, and how we applied that learn-
ing to the design and implementation of the RI. It is not prescriptive guidance and is not intended
to illustrate the only way to apply the CQRS approach to our RI. We have tried wherever possible
to capture alternative viewpoints through consultation with our advisors and to explain why we
made particular decisions. You may disagree with some of those decisions; please let us know at
[email protected].
This section of the written guidance makes frequent cross-references to the material in the sec-
ond section for readers who wish to explore any of the concepts or patterns in more detail.

CQRS reference
The second section of the written guidance is a collection of reference material collated from many
sources. It is not the definitive collection, but should contain enough material to help you to under-
stand the core patterns, concepts, and language of CQRS.

Tales from the trenches


This section of the written guidance is a collection of case studies from other teams that describe
their experiences of implementing the CQRS pattern and event sourcing in the real world. These case
studies are not as detailed as the journey section of the guidance and are intended to give an overview
of these projects and to summarize some of the key lessons learned.
The following is a list of the chapters that comprise both sections of the written guidance:

A CQRS journey
• Chapter 1, “The Contoso Conference Management System,” introduces our sample applica-
tion and our team of (fictional) experts.
• Chapter 2, “Decomposing the Domain,” provides a high-level view of the sample application
and describes the bounded contexts that make up the application.
• Chapter 3, “Orders and Registrations Bounded Context,” introduces our first bounded
context, explores some CQRS concepts, and describes some elements of our infrastructure.
• Chapter 4, “Extending and Enhancing the Orders and Registrations Bounded Context,”
describes adding new features to the bounded context and discusses our testing approach.
• Chapter 5, “Preparing for the V1 Release,” describes adding two new bounded contexts and
handling integration issues between them, and introduces our event-sourcing implementa-
tion. This is our first pseudo-production release.
• Chapter 6, “Versioning Our System,” discusses how to version the system and handle
upgrades with minimal down time.
• Chapter 7, “Adding Resilience and Optimizing Performance,” describes what we did to make
the system more resilient to failure scenarios and how we optimized the performance of the
system. This was the last release of the system in our journey.
• Chapter 8, “Lessons Learned,” collects the key lessons we learned from our journey and
suggests how you might continue the journey.
Another Random Scribd Document
with Unrelated Content
It was not very far from sunset, and the small birds were already
singing among the boughs, and the deep shadow—the antique and
neglected air and the silence of the place—gave it, in his romantic
eyes, a character of monastic mystery and enchantment.
As he gazed straight up the dark walk towards the house,
suddenly a man turned the corner of the yew hedge that met the
bridge’s parapet close to him, and walking straight up to the door,
with a gruff look at the little boy, shut and locked the wooden door in
his face.
So all was gone for the present. He knew there was no good in
looking through the key-hole, for envious fortune had hung a spray of
sweetbriar so as effectually to intercept the view, and nothing
remained but the dingy chocolate-coloured planks before him, and
the foliage and roses trembling over the old wall.
Many a time again he passed and re-passed the door without a
like good hap.
At length, however, one evening he found the envious wooden
door once more open, and the view again disclosed through the iron
bars.
A very pretty little girl, with golden hair, was standing on tip-toe
near, and with all her soul was striving to reach an apple with a stick
which she held in her tiny fingers.
Seeing him she fixed her large eyes on him, and said, with an air
of command—
“Come, and climb up the tree and get me that apple.”
His heart beat quick—there was nothing he liked better.
“But I can’t get in,” he said, blushing; “the door is locked.”
“Oh! I’ll call mamma—she’ll let you in. Don’t you know mamma?”
“No, I never saw her,” answered the boy.
“Wait there, and I’ll fetch her.”
And so she was gone.
The first flutter of his excitement was hardly over when he heard
steps and voices near, and the little girl returned, holding the hand of
a slight, pale lady, with a very pretty face, dressed all in black. She
had the key in her hand, and smiled gently on the little boy as she
approached. Her face was kind, and at once he trusted her.
“Oh! he has left the inner door open again,” she said, and with a
little nod and smile of welcome she opened the door, and the boy
entered the garden.
Both doors were now shut.
“Look up, little boy,” said the lady in black, with a very sweet voice.
She liked his face. He was a very handsome little fellow, and with
an expression earnest, shy, and bright, and the indescribable
character of refinement too in his face. She smiled more kindly still,
and placing just the tip of her finger under his chin she said—
“You are a gentleman’s son, and you are nicely dressed. What is
your name?”
“My papa’s name is Mr. Henry,” he answered.
“And where do you go to school?”
“I don’t go to school. I say lessons to Mr. Wharton—about half a
mile from this.”
“It is great fun, I suppose, playing with the little boys—cricket, and
all that?”
“I’m not allowed to play with the little boys.”
“Who forbids you?”
“My friends won’t allow me.”
“Who are your friends?”
“I never saw them.”
“Really! and don’t you live with your papa?”
“No, I live with Marjory.”
“Do you mean with your mamma?”
“Oh, no. She died a long time ago.”
“And is your papa rich—why aren’t you with him?”
“He was rich, Granny says, but he grew poor.”
“And where is he now?”
“I don’t know. I’m to go to school,” he said, acquiring confidence
the more he looked in that sweet face. “My friends will send me, in
three years, Granny says.”
“You are a very nice little boy, and I’m sure a good little fellow.
We’ll have tea in a few minutes—you must stay and drink tea with
us.”
The little fellow held his straw hat in his hand, and was looking up
in the face of the lady, whose slender fingers were laid almost
caressingly on his rich brown hair as she looked down smiling, with
eyes in which “the water stood.” Perhaps these forlorn childhoods
had a peculiar interest for her.
“And it is very polite of you taking off your hat to a lady, but put it
on again, for I’m not a bit better than you; and I’ll go and tell them to
get tea now. Dulcibella,” she called. “Dulcibella, this little friend is
coming to drink tea with us, and Amy and he will play here till it
comes, and don’t mind getting up, sit quiet and rest yourself.”
And she signed with her hand, smiling, to repress her attempt to
rise.
“Well, darling, play in sight o’ me, till your mamma comes back,”
said the rheumatic old woman, addressing the little girl; “and ye
mustn’t be pulling at that great rolling-stone; ye can’t move it, and ye
may break your pretty back trying.”
With these and similar injunctions the children were abandoned to
their play.
He found this pretty young lady imperious, but it was pleasant to
be so commanded, and the little boy climbed trees to gather her
favourite apples, and climbed the garden wall to pluck a bit of
wallflower, and at last she said—
“Now, we’ll play ninepins. There’s the box, set them up on the
walk. Yes, that’s right; you have played; who taught you?”
“Granny.”
“Has Granny ninepins?”
“Yes, ever so much bigger than these.”
“Really! So Granny is rich, then?”
“I think so.”
“As rich as mamma?”
“Her garden isn’t so big.”
“Begin, do you; ah, ha! you’ve hit one, and who plays best?”
“Tom Orange does; does your mamma know Tom Orange?”
“I dare say she does. Dulcibella, does mamma know Tom
Orange?”
“No, my dear.”
“No, she doesn’t,” echoed the little girl, “who is he?”
What, not know Tom Orange! How could that be? So he narrated
on that brilliant theme.
“Tom Orange must come to tea with mamma, I’ll tell her to ask
him,” decided the young lady.
So these little wiseacres pursued their game, and then had their
tea, and in about an hour the little boy found himself trudging home,
with a sudden misgiving, for the first time, as to the propriety of his
having made these acquaintances without Granny’s leave.
The kind voice, the beloved smile of Granny received him before
the cottage door.
“Welcome, darlin’, and where was my darlin’, and what kept him
from his old Granny?”
So they hugged and kissed, and then he related all that had
happened, and asked “was it any harm, Granny?”
“Not a bit, darlin’, that’s a good lady, and a grand lady, and a fit
companion for ye, and see how she knew the gentle blood in your
pretty face; and ye may go, as she has asked you, to-morrow
evening again, and as often as she asks ye; for it was only the little
fellows that’s going about without edication or manners, that your
friends, and who can blame them, doesn’t like ye to keep company
with—and who’d blame them, seeing they’re seldom out of mischief,
and that’s the beginning o’ wickedness, and you’re going, but oh!
darlin’, not for three long years, thank God, to a grand school where
there’s none but the best.”
So this chance acquaintance grew, and the lady seemed to take
every week a deeper interest in the fine little boy, so sensitive,
generous, and intelligent, and he very often drank tea with his new
friends.
CHAPTER LIX.
AN OLD FRIEND.

I am going now to describe the occurrences of a particular evening


on which my young friend drank tea at Stanlake Farm, which was the
name of the house with the old garden to which I have introduced
the reader.
A light shower had driven the party in from the garden, and so the
boy and Amy were at their ninepins in the great hall, when, the door
being open, a gentleman rode up and dismounted, placing the bridle
in the hand of a groom who accompanied him.
A tall man he was, with whiskers and hair dashed with white, and
a slight stoop. He strode into the hall, his hat on, and a whip still in
his hand.
“Hollo! So there you are—and how is your ladyship?” said he.
“Skittles, by the law! Brayvo! Two down, by Jove! I’d rather that
young man took you in hand than I. And tell me—where’s Ally?”
“Mamma’s in the drawing-room,” said the young lady, scarcely
regarding his presence. “Now play, it’s your turn,” she said,
addressing her companion.
The new arrival looked at the boy and paused till he threw the ball.
“That’s devilish good too,” said the stranger—“very near the nine.
Eh? But a miss is as good as a mile; and I don’t think he’s quite as
good as you—and she’s in the drawing-room; which is the drawing-
room?”
“Don’t you know the drawing-room! Well, there it is,” and the
young lady indicated it with her finger. “My turn now.”
And while the game was pursued in the hall, the visitor pushed
open the drawing-room door and entered.
“And how is Miss Ally?”
“Oh, Harry! Really!”
“Myself as large as life. You don’t look half pleased, Ally. But I
have nout but good news for you to-day. You’re something richer this
week than you were last.”
“What is it, Harry? Tell me what you mean?”
“So I will. You know that charge on Carwell—a hundred and forty
pounds a year—well, that’s dropped in. That old witch is dead—ye
might ’a seen it in the newspaper, if you take in one—Bertha
Velderkaust. No love lost between ye. Eh?”
“Oh, Harry! Harry! don’t,” said poor Alice, pale, and looking
intensely pained.
“Well, I won’t then; I didn’t think ’twould vex you. Only you know
what a head devil that was—and she’s dead in the old place,
Hoxton. I read the inquest in the Times. She was always drinkin’. I
think she was a bit mad. She and the people in the back room were
always quarrelling; and the father’s up for that and forgery. But
’twasn’t clear how it came about. Some swore she was out of her
mind with drink, and pitched herself out o’ the window; and some
thought it might ’a bin that chap as went in to rob her, thinkin’ she
was stupid; and so there was a tussle for’t—she was main strong, ye
know—and he chucked her out. Anyhow she got it awful, for she fell
across the spikes of the area-rails, and she hung on them with three
lodged in her side—the mad dog-fox, she was!”
“Oh, Harry! How shocking! Oh! pray don’t!” exclaimed Alice, who
looked as if she was going to faint.
“Well, she lay there, without breath enough to screech, twistin’ like
a worm—for three hours, it’s thought.”
“Oh! Harry—pray don’t describe it; don’t, I implore. I feel so ill.”
“Well, I won’t, if you say so, only she’s smashed, and cold in her
wooden surtout; and her charge is reverted to you, now; and I
thought I’d tell ye.”
“Thank you, Harry,” she said, very faintly.
“And when did you come here? I only heard this morning,” asked
Harry.
“Five weeks ago.”
“Do you like it; ain’t it plaguy lonesome?”
“I like the quiet—at least for a time,” she answered.
“And I’m thinkin’ o’ gettin’ married—upon my soul I am. What do
you think o’ that?”
“Really!”
“Sure as you’re there, but it won’t be none o’ your love-matches.
‘Bring something, lass, along wi’ thee,
If thou intend to live wi’ me.’
That’s my motto. Sweetheart and honey-bird keeps no house, I’ve
heard say. I like a body that can look after things, and that would
rather fund fifty pounds than spend a hundred.
‘A nice wife and a back door
Hath made many a rich man poor,’
as they say; and besides, I’m not a young fellow no longer. I’m
pushin’ sixty, and I should be wise. And who’s the little chap that’s
playin’ skittles wi’ Amy in the hall?”
“Oh, that’s such a nice little boy. His father’s name is Henry, and
his mother has been dead a long time. He lives with a good old
woman named Marjory Trevellian. What’s the matter, Harry?”
“Nothing. I beg your pardon. I was thinkin’ o’ something else, and I
didn’t hear. Tell me now, and I’ll listen.”
So she repeated her information, and Harry yawned and stretched
his arms.
“‘For want o’ company,
Welcome trumpery,’
and I must be goin’ now. I wouldn’t mind drinkin’ a glass o’ sherry, as
you’re so pressing, for I’ve had a stiff ride, and dust’s drouthy.”
So Harry, having completed his visit characteristically, took his
leave, and mounted his nag and rode away.
CHAPTER LX.
TOM ORANGE.

Little Miss Amy had a slight cold, and the next tea-party was put off
for a day. On the evening following Harry’s visit at Stanlake Farm,
Marjory Trevellian being at that time absent in the village to make
some frugal purchases, who should suddenly appear before the little
boy’s eyes, as he lifted them from his fleet upon the pond, but his
friend, Tom Orange, as usual in high and delightful spirits.
Need I say how welcome Tom was? He asked in a minute or two
for Marjory, and took her temporary absence with great good
humour. Tom affected chilliness, and indeed the evening was a little
sharp, and proposed that they should retire to the cottage, and sit
down there.
“How soon do you suppose, youngster, the old hen will come
home?”
“Who?”
“Marjory Daw, down the chimney.”
“Oh, Granny?”
This nickname was the only pleasantry of Mr. Orange which did
not quite please the boy.
Tom Orange here interpolated his performance of the jackdaw,
with his eyelids turned inside out and the pupils quivering, which,
although it may possibly have resembled the jackdaw of heraldry,
was not an exact portraiture of the bird familiar to us in natural
history; and when this was over he asked again—“How soon will she
be home?”
“She walked down to the town, and I think she can’t be more than
about half-way back again.”
“That’s a mile, and three miles an hour is the best of her paces if
she was runnin’ for a pound o’ sausages and a new cap. Heigh ho!
and alas and alack-a-day. No one at home but the maid, and the
maid’s gone to church! I wrote her a letter the day before yesterday,
and I must read it again before she comes back. Where does she
keep her letters?”
“In her work-box on the shelf.”
“This will be it, the wery identical fiddle!” said Tom Orange,
playfully, setting it down upon the little deal table, and, opening it, he
took out the little sheaf of letters from the end, and took them one by
one to the window, where he took the liberty of reading them.
I think he was disappointed, for he pitched them back again into
their nook in the little trunk-shaped box contemptuously.
The boy regarded Tom Orange as a friend of the family so
confidential, and as a man in all respects so admirable and virtuous,
that nothing appeared more desirable and natural than that excellent
person’s giving his attention to the domestic correspondence.
He popped the box back again in its berth. Then he treated the
young gentleman to Lingo’s song with the rag-tag-merry-derry
perrywig and hat-band, &c., and at the conclusion of the
performance admitted that he was “dry,” and with a pleasant wink,
and the tip of his finger pushing the end of his nose a good deal to
the left, he asked him whether he could tell him where Mrs.
Trevellian, who would be deeply grieved if she thought that Tom was
detained for a drink till her return, kept her liquor.
“Yes, I can show you,” said the boy.
“Wait a minute, my guide, my comforter, and friend,” said Tom
Orange; and he ascertained from the door-stone that no one was
inconveniently near.
The boy was getting a tea-cup off the shelf.
“Never mind sugar, my hero, I’ll sweeten it with a thought of
Marjory Daw.”
The boy explained, and led him into the dark nook by the hall door.
Tom Orange, well pleased, moved almost on tiptoe, and looked
curiously and spoke under his breath, as he groped in this twilight.
“Here it is,” said the boy, frankly.
“Where?”
“Here.”
“This!” said Tom, for his friend had uncovered a crock of water.
Tom Orange glared at him and at the water with grotesque
surprise, and the bona fides of the boy and the simplicity of the
situation struck Tom comically, and, exploding good-humouredly, he
sat down in Marjory’s chair and laughed hilariously.
Having satisfied himself by a confidential dialogue that Marjory
Daw had no private bottle of comfort anywhere, this agreeable fellow
so far forgot his thirst, that he did not mind drawing water from the
crock, and talked on a variety of subjects to the young gentleman. In
the course of this conversation he asked him two topographical
questions. One was—
“Did you ever hear of a place called Carwell Grange?”
And the other resembled it.
“Did you ever hear of a place called Wyvern?”
“No.”
“Think, lad. Did you never hear Mrs. Trevellian speak of Wyvern?
Or of Carwell Grange?”
“No.”
“Because there is the tallest mushroom you ever saw in your life
growing there, and it is grown to that degree that it blocks the door
so that the Squire can’t get into his own house, and the mushroom is
counted one of the wonders of the world upon my little word of
honour as a gentleman! And
‘Since there’s neither drink nor victuals,
Suppose, my lord, we play at skittles?’
And if she’s not back by the end of the game, tell her I had to go on
to the bridge to see lame Bill Withershins, and I’ll be back again this
evening, I think, or in the morning at latest.”
The game was played, but Marjory did not appear, and Tom
Orange, entertaining his young friend with a ludicrous imitation of Bill
Withershins’ knock-knees, took his departure, leaving his delighted
companion in the state which Moore describes as being usual—
“When the lamp that lighted
The traveller at first goes out.”
So, having watched Tom till he was quite out of sight, he returned
to his neglected navy on the pond, and delivered his admirable
Crichton’s message to Marjory Daw on her return.
CHAPTER LXI.
THE HOUR AND THE MAN.

Supper-time came, and Tom Orange did not return. Darkness


closed over the old cottage, the poplar trees and the town, and the
little boy said his prayers under the superintendence of worthy
Marjory, and went to his bed.
He was disturbed in his sleep by voices talking in the room. He
could only keep his eyes open for a little time, and he saw Tom
Orange talking with mammy. He was at one side of the little table
and she at another, and his head was leaning forward so as to
approach uncomfortably near to the mutton-fat with a long snuff in
the middle. Mammy, as he indiscriminately called “Granny,” was
sobbing bitterly into her apron, and sometimes with streaming eyes,
speaking so low that he could not hear, to Tom Orange.
Interesting as was the scene, slumber stole him away, and when
he next wakened, Tom was gone, and mammy was sitting on the
bed, crying as if her heart would break. When he opened his eyes,
she said—
“Oh, darlin’! darlin’! My man—my own, own blessed man—my
darlin’!” and she hugged him to her heart.
He remembered transports similar when two years ago he was
very ill of a fever.
“I’m not sick, mammy, indeed; I’m quite well,” and with these
assurances and many caresses, he again fell asleep.
In the morning his Sunday clothes, to his wonder, were prepared
for him to put on. The little old faded crimson carpet-bag, which she
had always told him, to the no small content of his self-importance,
was his own, stood plump and locked on the little table under the
clock. His chair was close beside mammy’s. She had all the
delicacies he liked best for his breakfast. There was a thin little slice
of fried bacon, and a new-laid egg, and a hot cake, and tea—quite a
grand breakfast.
Mammy sat beside him very close. Her arm was round him. She
was very pale. She tried to smile at his prattle, and her eyes filled up
as often as she looked at him, or heard him speak.
Now and then he looked wonderingly in her face, and she tried to
smile her old smile and nodded, and swallowed down some tea from
her cup.
She made belief of eating her breakfast, but she could not.
When the wondering little man had ended his breakfast, with her
old kind hands she drew him towards her.
“Sit down on my lap, my precious—my own man—my beautiful
boy—my own angel bright. Oh, darlin’—darlin’—darlin’!” and she
hugged the boy to her heart, and sobbed over his shoulder as if her
heart was bursting.
He remembered that she cried the same way when the doctor said
he was safe and sure to recover.
“Mammy,” he said, kissing her, “Amy has birthdays—and I think
this is my birthday—is it?”
“No, darlin’; no, no,” she sobbed, kissing him. “No, my darlin’, no.
Oh, no, ’taint that.”
She got up hastily, and brought him his little boots that she had
cleaned. The boy put them on, wondering, and she laced them.
With eyes streaming she took up one of the little cork boats, which
he kept on the window-stool floating in a wooden bowl.
“You’ll give me one of them, darlin’—to old mammy—for a
keepsake.”
“Oh! yes. Choose a good one—the one with the gold paper on the
pin; that one sails the best of all.”
“And—and”—she cried bitterly before she could go on—“and this
is the little box I’ll put them in,” and she picked them out of the bowl
and laid them in a cardboard box, which she quickly tied round. “And
this is the last day of poor mammy with her bright only darlin’—for
your friends are sending for you to-day, and Mr. Archdale will be here
in ten minutes, and you’re to go with him. Oh, my precious—the light
o’ the house—and to leave me alone.”
The boy stood up, and with a cry, ran and threw his arms round
her, where she stood near the clock.
“Oh! no, no, no. Oh! mammy, you wouldn’t; you couldn’t, you
couldn’t.”
“Oh, darlin’, you’re breaking my heart. What can I do?”
“Don’t let me go. Oh, mammy, don’t. Oh, you couldn’t, you
couldn’t.”
“But what can I do, darlin’? Oh, darlin’, what can I do?”
“I’ll run away, mammy, I’ll run away; and I’ll come back when
they’re gone, and stay with you.”
“Oh, God Almighty!” she cried, “here he’s coming. I see him
coming down the hazel road.”
“Hide me, mammy; hide me in the press. Oh, mammy, mammy,
you wouldn’t give me to him!”
The boy had got into this large old-painted press, and coiled
himself up between two shelves. There was hardly a moment to
think; and yielding to the instinct of her desperate affection, and to
the child’s wild appeal, she locked the door, and put the key in her
pocket.
She sat down. She was half stunned by her own audacity. She
scarcely knew what she had done. Before she could recover herself,
the door darkened, a hand crossed the hatch and opened it, and ex-
Sergeant-Major Archdale entered the cottage.
In curt military fashion he announced himself, and demanded the
boy.
She was looking straight in this formidable man’s face, and yet it
seemed as if he were vanishing from before her eyes.
“Where’s the boy?” inquired the chill stern voice of the Sergeant.
It seemed to her like lifting a mountain this effort to speak. She felt
as if she were freezing as she uttered the denial.
“He aint here.”
“Where is he?” demanded the Sergeant’s imperturbably clear cold
voice.
“He’s run away,” she said with an effort, and the Sergeant seemed
to vanish quite away, and she thought she was on the point of
fainting.
The Sergeant glanced at the breakfast table, and saw that two had
taken tea together; he saw the carpet-bag packed.
“H’m?” intimated Archdale, with closed lips. He looked round the
cottage room, and the Sergeant sat down wonderfully composed,
considering the disconcerting nature of the announcement.
The ex-Sergeant-Major had in his time commanded parties in
search of deserters, and he was not a bad slaught-hound of that
sort.
“He breakfasted with you?” said he, with a cool nod toward the
table.
There was a momentary hesitation, and she cleared her voice and
said—
“Yes.”
Archdale rose and placed his fingers on the teapot.
“That’s hot,” said the Sergeant with the same inflexible dignity.
Marjory was awfully uneasy.
“He can’t be far. Which way did he go?”
“Out by the door. I can’t tell.”
The ex-Sergeant-Major might have believed her the goddess of
truth itself, or might have thought her the most impudent liar in
England. You could not have gathered in the least from his
countenance toward which view his conclusions tended.
The Sergeant’s light cold grey eye glided again round the room,
and there was another silence awfully trying to our good friend
Marjory.
CHAPTER LXII.
THE MARCH TO NOULTON FARM.

“I think, ma’am, the boy’s in the house. You’d best give him up, for
I’ll not go without him. How many rooms have you?”
“Three and a loft, sir.”
The Sergeant stood up.
“I’ll search the house first, ma’am, and if he’s not here I’ll inform
the police and have him in the Hue-and-Cry; and if you have had
anything to do with the boy’s deserting, or had a hand in making
away with him anyhow, I’ll have you in gaol and punished. I must
secure the door, and you can leave the house first, if you like best.”
“Very well, sir,” answered she.
But at this moment came a knocking and crying from within the
press.
“Oh! no—’twasn’t mammy; ’twas I that did it. Don’t take mammy.”
“You see, ma’am, you give useless trouble. Please open that door
—I shall have to force it, otherwise,” he added, as very pale and
trembling she hesitated.
Standing as he might before his commanding officer, stiff, with his
heels together, with his inflexibly serene face, full before her, he
extended his hand, and said simply, “The key, ma’am.”
In all human natures—the wildest and most stubborn—there is a
point at which submission follows command, and there was that in
the serenity of the ex-Sergeant-Major which went direct to the
instinct of obedience.
It was quite idle any longer trying to conceal the boy. With a
dreadful ache at her heart she put her hand in her pocket and
handed him the key.
As the door opened the little boy shrank to the very back of the
recess, from whence he saw the stout form of the Sergeant stooped
low, as his blue, smooth fixed countenance peered narrowly into the
dark. After a few seconds he seemed to discern the figure of the boy.
“Come, you sir, get out,” said the commanding voice of the visitor,
as the cane which he carried in his hand, paid round with wax-end
for some three inches at the extremity, began switching his little legs
smartly.
“Oh, sir, for the love of God!” cried Marjory, clinging to his hand.
“Oh, sir, he’s the gentlest little creature, and he’ll do whatever he’s
bid, and the lovingest child in the world.”
The boy had got out by this time, and looking wonderingly in the
man’s face, was unconsciously, with the wincing of pain, lifting his
leg slightly, for the sting of the cane was quite new to him.
“If I catch you at that work again I’ll give you five dozen,” said his
new acquaintance.
“Is this his?” said he, touching the carpet-bag with his cane.
“Yes, sir, please.”
He took it in his hand, and glanced at the boy—I think it was in his
mind to make him carry it. But the child was slender, and the bag,
conscientiously packed with everything that had ever belonged to
him, was a trifle too heavy.
“Anything else?” demanded the Sergeant-Major.
“This—this, God bless him.”
It was the little box with his ships.
“And this;” and she thrust the griddle cake, broken across and
rolled up in brown paper, into the boy’s pocket.
“And these;” and three apples she had ready, she thrust after
them.
“And ho! my blessed darlin’, my darlin’, darlin’, darlin’.”
He was lifted up against her heart, folded fast, and hugging her
round the neck, they kissed and cried and cried and kissed, and at
last she let him down; and the Sergeant-Major, with the cane under
his arm, the carpet-bag in one hand, and the boy’s wrist firmly held in
the other, marched out of the door.
“That’s enough—don’t follow, woman,” said he, after they had
gone about twenty yards on the path; “and I’ll report you,” he added
with a nod which, with these pleasant words, she might take as a
farewell or not as she pleased.
She stood on the little rising ground by the hawthorn-tree, kissing
her hands wildly after him, with streaming eyes.
“I’ll be sure to see you soon. I’d walk round the world barefoot to
see my pretty man again,” she kept crying after him; “and I’ll bring
the ninepins, I’ll be sure. Mammy’s comin’, my darlin’.”
And the receding figure of the little boy was turned toward her all it
could. He was gazing over his shoulder, with cheeks streaming with
tears, and his little hand waving yearningly back to her until he was
out of sight. And after a while she turned back, and there was their
ninepins’ ground, and the tarn, and her sobs quickened almost to a
scream; and she sat down on the stone bench under the window—
for she could not bear to enter the dark cottage—and there, in Irish
phrase, she cried her fill.
In the meantime Archdale and his companion, or prisoner—which
you will—pursued their march. He still held the boy’s wrist, and the
boy cried and sobbed gently to himself all the way.
When they came down to the little hamlet called Maple Wickets he
hired a boy to carry the carpet-bag to Wunning, four miles further on,
where the Warhampton ’bus passes, as everybody knows, at half-
past twelve o’clock daily.
They resumed their march. The Sergeant was a serenely taciturn
man. He no more thought of addressing the boy than he did of
apostrophising the cane or the carpet-bag. He let him sob on, and
neither snubbed nor consoled him, but carried his head serene and
high, looking straight before him.
At length the novelty of the scene began to act upon the volatility
of childhood.
As he walked by the Sergeant he began to prattle, at first timidly,
and then more volubly.
The first instinct of the child is trust. It was a kind of consolation to
the boy to talk a great deal of his home, and Tom Orange was of
course mentioned with the usual inquiry, “Do you know Tom
Orange?”
“Why so?”
Then followed the list of that facetious and brilliant person’s
accomplishments.
“And are we to go near a place called Wyvern or Carwell Grange?”
asked the boy, whose memory, where his fancy was interested, was
retentive.
“Why so?” again demanded the Sergeant, looking straight before
him.
“Because Tom Orange told me there’s the biggest mushroom in
the world grown up there, and that the owner of the house can’t get
in, for it fills up the door.”
“Tom Orange told you that?” demanded the Sergeant in the same
way.
And the boy, supposing it incredulity on his part, assured him that
Tom, who was truth itself, had told him so only yesterday.
The Sergeant said no more, and you could not have told in the
least by his face that he had made a note of it and was going to
“report” Tom Orange in the proper quarter. And in passing, I may
mention that about three weeks later Tom Orange was peremptorily
dismissed from his desultory employments under Mr. Archdale, and
was sued for stealing apples from Warhampton orchard, and some
minor peccadillos, and brought before the magistrates, among whom
sat, as it so happened, on that occasion, Squire Fairfield of Wyvern,
who was “precious hard on him,” and got him in for more than a
month with hard labour. The urchin hireling with the carpet-bag
trudged on in front as the Sergeant-Major had commanded.
Our little friend, with many a sobbing sigh, and a great load at his
heart, yet was looking about him.
They were crossing a moor with beautiful purple heather, such as
he had never seen before. The Sergeant had let go his wrist. He felt
more at his ease every way.
There were little pools of water here and there which attracted the
boy’s attention, and made him open his box of cork boats and peep
at them. He wondered how they would sail in these dark little nooks,
and at last, one lying very conveniently, he paused at its margin, and
took out a ship and floated it, and another, and another. How quickly
seconds fly and minutes.
He was roused by the distant voice of the Sergeant-Major
shouting, “Hollo, you sir, come here.”
He looked up. The Sergeant was consulting his big silver watch as
he stood upon a little eminence of peat.
By the time he reached him the Sergeant had replaced it, and the
two or three seals and watchkey he sported were dangling at the end
of his chain upon his paunch. The Sergeant was standing with his
heels together and the point of his cane close to the side of his boot.
“Come to the front,” said the Sergeant.
“Give up that box,” said he.
The boy placed it in his hand. He uncovered it, turned over the
little navy with his fingers, and then jerked the box and its contents
over the heath at his side.
“Don’t pick one of ’em up,” said he.
“Move half a pace to the right,” was his next order.
His next command was—
“Hold out your hand.”
The boy looked in his face, surprised.
The Sergeant’s face looked not a bit angrier or a bit kinder than
usual. Perfectly serene.
“Hold out your hand, sir.”
He held it out, and the cane descended with a whistling cut across
his fingers. Another. The boy’s face flushed with pain, and his
deadened hand sunk downward. An upward blow of the cane across
his knuckles accompanied the command, “Hold it up, sir,” and a third
cut came down.
The Sergeant was strong, and could use his wrist dexterously.
“Hold out the other;” and the same discipline was repeated.
Mingled with and above the pain which called up the three great
black weals across the slender fingers of each hand, was the sense
of outrage and cruelty.
The tears sprang to his eyes, and for the first time in his life he
cried passionately under that double anguish.
“Walk in front,” said the Sergeant, serenely.
And squeezing and wringing his trembling hands together, the still
writhing little fellow marched along the path, with a bitterer sense of
desolation than ever.
The ’bus was late at Wunning; and a lady in it, struck by the
beauty and sadness of the little boy’s face, said some kind words,
and seemed to take to him, he thought, with a tenderness that made
his heart fuller; and it was a labour almost too great for him to keep
down the rising sobs and the tears that were every moment on the
point of flowing over. This good Samaritan bought a bag of what
were called “Ginger-bread nuts”—quite a little store; which Archdale
declined leaving at the boy’s discretion. But I am bound to say that
they were served out to him, from day to day, with conscientious
punctuality by the Sergeant-Major, who was strictly to be depended
on in all matters of property; and would not have nibbled at one of
those nuts though his thin lips had watered and not a soul had been
near. He must have possessed a good many valuable military
virtues, or he could not, I presume, have been where he was.
Noulton Farm is a melancholy but not an ugly place. There are a
great many trees about it. They stand too near the windows. The
house is small and old, and there is a small garden with a thick high
hedge round it.
The members of the family were few. Miss Mary Archdale was ill
when they arrived. She was the only child of the ex-Sergeant, who
was a widower; and the new inmate of the house heard of her with a
terror founded on his awe of her silent father.
They entered a small parlour, and the boy sat down in the chair
indicated by the Sergeant. That person hung his hat on a peg in the
hall, and placed his cane along the chimney-piece. Then he rang the
bell.
The elderly woman who was the female staff of the kitchen
entered. She looked frightened, as all that household did, in their
master’s presence, and watched him with an alarmed eye.
“Where’s Miss Mary?”
“A-spitting blood, sir, please.”
“Bring in supper,” said the Sergeant.
The boy sat in fear at the very corner of the table. His grief would
not let him eat, and he sipped a cup of tea that was too hot, and had
neither milk nor sugar enough. The Sergeant snuffed his candle, and
put on a pair of plated spectacles, and looked through his weekly
paper.
While he was so employed there glided into the room a very slight
girl, with large eyes and a very pale face. Her hair was brown and
rich.
The hand with which she held her shawl across was very thin; and
in her pale face and large eyes was a timid and imploring look that

You might also like