Leanpub Header

Skip to main content

Event-Driven Architecture & DDD in TypeScript. Event Sourcing, CQRS, and Microservices at Scale

Interested in this book? Show your support by saying what you'd like to pay for it!

$
EPUB
About

About

About the Book

Master Enterprise-Grade Event-Driven Architecture, DDD, CQRS, and Event Sourcing in TypeScript & Node.js!

When enterprise systems fail under heavy load, the root cause is rarely technical incompetence—it is a semantic mismatch between complex business rules and fragile, monolithic CRUD database designs. In Volume 28 of the Series, author Edgar Milvus delivers a definitive, production-ready masterclass on designing, building, and scaling event-driven microservices using TypeScript.

Learn how to abandon destructive database updates in favor of Immutable Event Streams, protecting business invariants at compile-time and runtime while scaling read and write workloads independently.

What’s Inside This Comprehensive Guide:

  • Strategic & Tactical Domain-Driven Design (DDD): Enforce Bounded Contexts, design rich Aggregates, build immutable Value Objects with branded types, and eliminate primitive obsession.
  • Append-Only Event Sourcing Core: Build an Event Store from scratch, enforce Optimistic Concurrency Control (OCC), and optimize aggregate hydration using Redis L1/L2 Snapshots.
  • CQRS & Asynchronous Projections: Sever reads from writes. Construct idempotent PostgreSQL read models tailored for sub-millisecond API and UI queries.
  • The Transactional Outbox Pattern: Eliminate the dual-write problem using PostgreSQL SKIP LOCKED polling, Change Data Capture (CDC / Debezium), and atomic transactions.
  • Event Broker Mastery: Deep-dive architectural comparisons and code implementations for Apache Kafka, RabbitMQ, and NATS JetStream in Node.js.
  • Distributed Sagas & Error Recovery: Orchestrate long-running transactions with state machines, compensating rollbacks, Dead-Letter Queues (DLQ), and Circuit Breakers.
  • Schema Evolution & Upcasting: Evolve event schemas across years of operation without breaking historical replay or current domain models.
  • Distributed Tracing with OpenTelemetry: Propagate W3C Trace Contexts across asynchronous broker boundaries, correlate logs, and eliminate distributed debugging blind spots.

Packed with theoretical rigor, modern analogies (React Server Components, Virtual DOM, ESM), common pitfalls, and full-stack code examples using Zod, Prisma, OpenTelemetry, and React/TSX, this book is your ultimate blueprint for building enterprise microservices that scale effortlessly.

Take your TypeScript backend architecture to the enterprise level !

Table of contents

Chapter 1: Ubiquitous Language & Bounded Contexts in TypeScript

Chapter 2: Value Objects and Entities - Immutability & Validation

Chapter 3: Aggregates & Domain Boundaries - Protecting Business Invariants

Chapter 4: Modeling Domain Events with TypeScript Discriminated Unions

Chapter 5: Domain Repositories & In-Memory Implementations for Testing

Chapter 6: Decoupling Reads and Writes - Intro to CQRS in TypeScript

Chapter 7: The Write Model - Command Handlers & State Transitions

Chapter 8: Event Sourcing Core - Building an Append-Only Event Store

Chapter 9: The Read Model - Building Event-Driven Projections with PostgreSQL

Chapter 10: Performance & Snapshots in Event-Sourced Systems

Chapter 11: Choosing Event Brokers - Kafka vs RabbitMQ vs NATS in Node.js

Chapter 12: Reliable Event Publishing with the Transactional Outbox Pattern

Chapter 13: Idempotent Event Handlers & At-Least-Once Delivery Guarantees

Chapter 14: Event Schema Evolution and Versioning Strategies

Chapter 15: Dead-Letter Queues & Error Recovery Workflows

Chapter 16: Orchestrating Long-Running Transactions - The Saga Pattern

Chapter 17: Distributed Tracing & Observability for Event Streams with OpenTelemetry

Chapter 18: Testing DDD & Event-Sourced Applications (Unit & Integration)

Chapter 19: Security, Authorization & Tenant Isolation in Distributed Events

Chapter 20: Capstone - Building an Enterprise-Grade E-Commerce & Order Management Core

If printed, this ebook would span over 400 pages. Each chapter is structured into theoretical foundations, an annotated basic example, an annotated advanced example, and five coding exercises based on real-world scenarios with complete solutions.

Share this book

Author

About the Author

Edgar Milvus

A veteran software engineer with 20 years of experience, I have dedicated my career to the art of automation. My philosophy is simple: programming should eliminate repetitive chores to unlock human creativity. This journey began early on with the development of custom code-generation tools and has evolved into a deep mastery of LLMs and their APIs. Today, I specialize in architecting AI-driven solutions that handle everything from complex coding and security tasks to advanced knowledge retrieval, transforming the way we interact with technology

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub