Begin building event-driven microservices, including patterns to handle data consistency and resiliency Key Features Explore the benefits and tradeoffs of event-driven architectures with practical examples and use cases Understand synergy with event sourcing, CQRS, and domain-driven development
Event-Driven Architecture in Golang: Building complex systems with asynchronicity and eventual consistency
โ Scribed by Michael Stack
- Publisher
- Packt Publishing
- Year
- 2022
- Tongue
- English
- Leaves
- 384
- Category
- Library
No coin nor oath required. For personal study only.
โฆ Synopsis
Begin building event-driven microservices, including patterns to handle data consistency and resiliency
Key Features
- Explore the benefits and tradeoffs of event-driven architectures with practical examples and use cases
- Understand synergy with event sourcing, CQRS, and domain-driven development in software architecture
- Build an end-to-end robust application architecture by the end of the book
Book Description
Event-driven architecture in Golang is an approach used to develop applications that shares state changes asynchronously, internally, and externally using messages. EDA applications are better suited at handling situations that need to scale up quickly and the chances of individual component failures are less likely to bring your system crashing down. This is why EDA is a great thing to learn and this book is designed to get you started with the help of step-by-step explanations of essential concepts, practical examples, and more.
You'll begin building event-driven microservices, including patterns to handle data consistency and resiliency. Not only will you learn the patterns behind event-driven microservices but also how to communicate using asynchronous messaging with event streams. You'll then build an application made of several microservices that communicates using both choreographed and orchestrated messaging.
By the end of this book, you'll be able to build and deploy your own event-driven microservices using asynchronous communication.
What you will learn
- Understand different event-driven patterns and best practices
- Plan and design your software architecture with ease
- Track changes and updates effectively using event sourcing
- Test and deploy your sample software application with ease
- Monitor and improve the performance of your software architecture
Who this book is for
This hands-on book is for intermediate-level software architects, or senior software engineers working with Golang and interested in building asynchronous microservices using event sourcing, CQRS, and DDD. Intermediate-level knowledge of the Go syntax and concurrency features is necessary.
Table of Contents
- Introduction to Event-Driven Architectures
- Supporting Patterns In Brief
- Design and Planning
- Event Foundations
- Tracking Changes with Event Sourcing
- Asynchronous Connections
- Event-carried State Transfer
- Event Workflows
- Transactional Messaging
- Testing
- Deploying applications to the cloud
- Monitoring and Observability
โฆ Table of Contents
Cover
Title Page
Copyright and Credits
Dedication
Contributors
Table of Contents
Preface
Part 1: Event-Driven Fundamentals
Chapter 1: Introduction to Event-Driven Architectures
Technical requirements
An exchange of facts
Event notifications
Event-carried state transfer
Event sourcing
Core components
Wrap-up
The MallBots application
The pitch
Application services
API gateway services
Clients
A quick note about hexagons
Benefits of EDA
Resiliency
Agility
User experience (UX)
Analytics and auditing
Challenges of EDA
Eventual consistency
Dual writes
Distributed and asynchronous workflows
Debuggability
Getting it right
Summary
Chapter 2: Supporting Patterns in Brief
Domain-driven design
DDD misconceptions
So, what is it all about then?
How is it useful for EDA?
Domain-centric architectures
An evolving solution
Hexagonal architecture applied
Testing
A rulebook, not a guidebook
Should you use domain-centric architectures?
How is it useful for EDA?
Command and Query Responsibility Segregation
The problem being solved
Applying CQRS
When to consider CQRS
CQRS and event sourcing
Task-based UI
Application architectures
Monolithic architecture
Microservices
Recommendation for green field projects
Summary
Further reading
Chapter 3: Design and Planning
Technical requirements
What are we building?
Finding answers with EventStorming
What is EventStorming?
Big Picture EventStorming
Design-level EventStorming
Understanding the business
Recording architectural decisions
Summary
Further reading
Part 2: Components of Event-Driven Architecture
Chapter 4: Event Foundations
Technical requirements
A tour of MallBots
The responsibilities of the monolith
Module code organization
User interface
Running the monolith
A focus on event-driven integration and communication patterns
Taking a closer look at module integration
Using external data
Commanding external components
Types of events
Domain events
Event sourcing events
Integration events
Refactoring side effects with domain events
What about the modules not using DDD?
Summary
Chapter 5: Tracking Changes with Event Sourcing
Technical requirements
What is event sourcing?
Understanding the difference between event streaming and event sourcing
Adding event sourcing to the monolith
Beyond basic events
Adding the event sourcing package
Using just enough CQRS
A group of stores is called a mall
A group of products is called a catalog
Taking note of the little things
Connecting the domain events with the read model
Recapping the CQRS changes
Aggregate event stream lifetimes
Taking periodic snapshots of the event stream
Using snapshots
Summary
Chapter 6: Asynchronous Connections
Technical requirements
Asynchronous integration with messages
Integration with notification events
Integration with event-carried state transfer
Eventual consistency
Message-delivery guarantees
Idempotent message delivery
Ordered message delivery
Implementing messaging with NATS JetStream
The am package
The jetstream package
Making the Store Management module asynchronous
Modifying the monolith configuration
Updating the monolith application
Providing to the modules the JetStreamContext
Publishing messages from the Store Management module
Receiving messages in the Shopping Baskets module
Verifying we have good communication
Summary
Chapter 7: Event-Carried State Transfer
Technical requirements
Refactoring to asynchronous communication
Store Management state transfer
Customer state transfer
Order processing state transfer
Payments state transfer
Documenting the asynchronous API
Adding a new order search module
Building read models from multiple sources
Creating a read model record
Summary
Chapter 8: Message Workflows
Technical requirements
What is a distributed transaction?
Why do we need distributed transactions?
Comparing various methods of distributed transactions
The 2PC
The Saga
Implementing distributed transactions with Sagas
Adding support for the Command and Reply messages
Adding an SEC package
Converting the order creation process to use a Saga
Adding commands to the saga participants
Implementing the create order saga execution coordinator
Summary
Chapter 9: Transactional Messaging
Technical requirements
Identifying problems faced by distributed applications
Identifying problems in synchronous applications
Identifying problems in asynchronous applications
Examining potential ways to address the problem
The singular write solution
Exploring transactional boundaries
How the implementation will work
The di package
Updating the Depot module with dependency containers
Using an Inbox and Outbox for messages
Implementing a messages inbox
Implementing a messages outbox
Summary
Part 3: Production Ready
Chapter 10: Testing
Technical requirements
Coming up with a testing strategy
Unit tests
Integration tests
Contract tests
End-to-end tests
Testing the application and domain with unit tests
Table-driven testing
Creating and using test doubles in our tests
Testing dependencies with integration testing
Incorporating the dependencies into your tests
Running tests with more complex setups
Testing ProductCacheRepository
Breaking tests into groups
Testing component interactions with contract tests
Consumer expectations
Provider verifications
Not building any silos
Contract testing with Pact
REST consumer and provider example
Message consumer and provider example
Testing the application with end-to-end tests
Relationship with behavior-driven development
E2E test organization
Making executable specifications out of our features
What to test or not test
Summary
Chapter 11: Deploying Applications to The Cloud
Technical requirements
Turning the modular monolith into microservices
Refactoring the monolith construct
Updating the composition root of each module
Making each module run as a service
Updates to the Dockerfile build processes
Updates to the Docker Compose file
Adding a reverse proxy to the compose environment
Fixing the gRPC connections
Installing the necessary DevOps tools
Installing every tool into a Docker container
Installing the tools into your local system
Using Terraform to configure an AWS environment
Preparing for the deployment
A look at the AWS resources we are deploying
Deploying the infrastructure
Viewing the Kubernetes environment
Deploying the application to AWS with Terraform
Getting to know the application resources to be deployed
Deploying the application
Tearing down the application and infrastructure
Summary
Chapter 12: Monitoring and Observability
Technical requirements
What are monitoring and observability?
The three pillars of observability
How tracing works
Instrumenting the application with OpenTelemetry and Prometheus
Adding distributed tracing to the application
Adding metrics to the application
Viewing the monitoring data
Summary
Index
About Packt
Other Books You May Enjoy
๐ SIMILAR VOLUMES
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 w
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 w
<div><p>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 s
<div><p>Reactive systems and event-driven architecture are becoming indispensable to application design, and companies are taking note. Reactive systems ensure that applications are responsive, resilient, and elastic no matter what failures or errors may be occurring, while event-driven architecture
The exponential growth of data combined with the need to derive real-time business value is a critical issue today. An event-driven data mesh can power real-time operational and analytical workloads, all from a single set of data product streams. With practical real-world examples, this book shows y