small medium large xlarge

Practical Microservices: Build Event-Driven Architectures with Event Sourcing and CQRS


Cover image for Practical Microservices

Practical Microservices

Build Event-Driven Architectures with Event Sourcing and CQRS


MVC and CRUD make software easier to write, but harder to change. Microservice-based architectures can help even the smallest of projects remain agile in the long term, but most tutorials meander in theory or completely miss the point of what it means to be microservice-based. Roll up your sleeves with real projects and learn the most important concepts of evented architectures. You’ll have your own deployable, testable project and a direction for where to go next.

Choose Your Format(s)

  • $24.95 In Stock
    • Beta: What do I get?

  • Ebooks are DRM free.

  • Ebook delivery options.

About this Title

Pages: 250 (est)
Published: 2020-04-10
Release: B7.0 (2020-02-14)
ISBN: 978-1-68050-645-7

Much ink has been spilled on the topic of microservices, but all of this writing fails to accurately identify what makes a system a monolith, define what microservices are, or give complete, practical examples, so you’re probably left thinking they have nothing to offer you. You don’t have to be at Google or Facebook scale to benefit from a microservice-based architecture. Microservices will keep even small and medium teams productive by keeping the pieces of your system focused and decoupled.

Discover the basics of message-based architectures, render the same state in different shapes to fit the task at hand, and learn what it is that makes something a monolith (it has nothing to do with how many machines you deploy to). Conserve resources by performing background jobs with microservices. Deploy specialized microservices for registration, authentication, payment processing, e-mail, and more. Tune your services by defining appropriate service boundaries. Deploy your services effectively for continuous integration. Master debugging techniques that work across different services. You’ll finish with a deployable system and skills you can apply to your current project.

Add the responsiveness and flexibility of microservices to your project, no matter what the size or complexity.

What You Need

While the principles of this book transcend programming language, the code examples are in Node.js because JavaScript, for better or worse, is widely read. You’ll use PostgreSQL for data storage, so familiarity with it is a plus. The books does provide Docker images to make working with PostgreSQL a bit easier, but extensive Docker knowledge is not required.

Contents & Extracts

This book is currently in beta, so the contents and extracts will change as the book is developed.

  • Introduction
    • Principles vs. implementations
    • Putting the “micro” in microservices
    • Node.js
  • You Have a New Project excerpt
    • Kicking Off Video Tutorials
    • Building the Bones
    • Mounting Middleware
    • Injecting Dependencies
    • Taking the Server for a Spin and Starting the Database
    • Serving the Home Page
    • Connecting the Home Page Application
    • Mounting the Home Application into Express
    • Building the Record Views Application
    • Recording State Changes
    • Charting a New Course
    • What You’ve Done So Far
  • Writing Messages
    • Unmasking the Monolith
    • Trying to Compress Water
    • Extracting “Microservices”
    • Defining Services
    • Getting Services to Do Things
    • Representing Messages in Code excerpt
    • Naming Messages
    • Storing State as Events
    • Storing Messages in Streams
    • Recording Video Views
    • Writing Your First Message
    • (Re)configuring the Record-Viewings Application
    • Hanging a Lantern
    • What You’ve Done So Far
  • Putting Data in a Message Store
    • Defining Requirements
    • Fleshing Out Message Structure
    • Storing Messages
    • Mapping the Write Flow
    • Coordinating the Message Write Flow
    • Making Sure the Commit Row Is In Place
    • Loading the Commit Row
    • Validating Expected Version (If We Have To)
    • Generating the Next Message Version
    • Actually Inserting the Message
    • Updating the Commit Row
    • Building the Message Store Interface
    • What You’ve Done So Far
  • Projecting Data into Useful Shapes
    • Handling Events
    • (Re)Introducing the RDBMS
    • Writing Your First Aggregator
    • Handling Asynchronous Messages excerpt
    • Getting Idempotent with It
    • Connecting to the Live Message Flow
    • Configuring the Aggregator
    • Having the Home Page Application Use The New Read Model
    • Coming to Terms with Data Duplication
    • What You’ve Done So Far
  • Subscribing to the Message Store
    • Sketching the Subscription Process
    • Managing the Current Read Position
    • Fetching and Processing Batches of Messages
    • Orchestrating the Subscription
    • Reading the Last Message in a Stream
    • Reading All of a Stream’s Messages
    • Adding the Read Functions to the Message Store’s Interface
    • What You’ve Done So Far
  • Registering Users
    • Discovering Domain Messages
    • Starting with the Business Process
    • Translating the Business Processes into Events and Commands
    • Fleshing Out the Identity Messages
    • Examples from Other Domains
    • Adding Registration to Our System
    • Turning Registration Requests into Commands
    • Superficially Validating User Input
    • Ensuring Uniqueness of Email Addresses
    • Finishing the Application
    • Validating Eventually Consistent Data
    • Coping with Tradeoffs
    • What You’ve Done So Far
  • Implementing Your First Service
    • Fetching a Stream’s Current State
    • Joining the “I Wrote a Microservice” Club
    • Wiring the Identity Service into the System
    • Disambiguating “Projections” and “Replaying”
    • Taking It Further
    • What You’ve Done So Far
  • Authenticating Users
    • Aggregating UserRegistration Events
    • Discovering the Authentication Events and Commands
    • Letting Users in the Door
    • Using Third-Party Authentication
    • What You’ve Done So Far
  • Adding an Email Service
    • Discovering the Email Service Messages
    • Addressing Idempotence
    • Adding the Service
    • Sending the Email
    • Running the Service
    • Revisiting Idempotence
    • What You’ve Done So Far
  • Performing Background Jobs With Microservices
    • Accidental Complexity
    • Use Case #1: Sending Emails
    • Use Case #2: Transcoding Videos
    • Describing the Creators Portal
    • Aggregating Is Also for Other Teams
    • Building the Video Publishing Service
    • Accepting Potential Duplication
    • What You’ve Done So Far
  • Building Async-Aware User Interfaces
    • Defining Video Metadata Messages
    • Responding to Users When the Response Isn’t Immediately Available
    • Adding Validation to a Service
    • Aggregating Naming Results
    • Applying Naming Events to the Creators Portal Read Model
    • Justifying our UI Decision
    • What You’ve Done So Far
  • Determining Service Boundaries
    • Push Vs Pull
  • Evolving the message contract
    • Changing an Existing Flow
  • CRUDing Up A Services Architecture
  • Deploying Services
  • Debugging Services
  • Continuing the Journey
    • Concurrency
    • Modeling Time
  • ES6 Syntax
  • Setting up Docker
  • Intro to Express and Pug
    • Middleware
  • Working with knex


Ethan’s love of computer programming began at age 4 when his dad taught him to make the family TI-99/4A beep. For the past 12 years Ethan has worked professionally up and down the abstraction hierarchy, from junior developer up to platform architect, finally settling into microservice-based architectures for the past 3 years.

Upcoming Author Events

  • 2020-02-24: Ethan Garofolo
    Practical microservices: Hands-on event-driven architectures with event sourcing and CQRS A 3.5-hour, hands-on workshop in which you'll get practical experience building event-driven microservice-based architectures. (O'Reilly Software Architecture Conference, New York City)
  • 2020-03-25: Ethan Garofolo
    Building UIs for Microservices: UI implications when dealing with asynchronous microservices. (, Broomfield, Colorado)