Serverless Clean Architecture & Code with Domain-Driven Design — Part 2 🚀: Building Serverless Microservices with Event-Driven Architecture and EventBridge

tfc

Hatched by tfc

Feb 25, 2024

4 min read

0

Serverless Clean Architecture & Code with Domain-Driven Design — Part 2 🚀: Building Serverless Microservices with Event-Driven Architecture and EventBridge

Introduction:

In the world of serverless architecture, it is crucial to have a clean and well-designed codebase that follows domain-driven design principles. This article explores the concepts of serverless clean architecture, code organization, and the role of event-driven architecture in building serverless microservices. We will also dive into the features and benefits of AWS EventBridge, a fully-managed serverless event bus, and its role in event routing and integration.

Understanding Aggregates and Entities in Domain-Driven Design:

In domain-driven design, an aggregate is a cluster of associated objects that are treated as a unit for data changes. Each aggregate has a root entity that represents the main object within the aggregate. The root entity is the only member of the aggregate that outside objects can hold references to. Other entities within the aggregate have local identities and are distinguishable only within the context of the root entity. This concept of aggregates and entities helps in organizing code and maintaining data integrity within a serverless architecture.

Software Architecture for Building Serverless Microservices:

Event-driven architecture (EDA) plays a crucial role in building serverless microservices. In EDA, event producers create and publish events, while event consumers subscribe to events and handle them according to their logic. EventBridge is a powerful service that acts as an event carrier, accepting events from producers and delivering them to subscribers. It supports event filtering, transformation, and routing, making it an essential component of serverless microservices.

EventBridge as an Event Router Ecosystem:

EventBridge provides a comprehensive event router ecosystem, where event buses act as individual channels of event flow. Event producers choose the event bus to send their events, and event routing is configured on each bus. This flexibility allows for efficient event management and decoupling of microservices. EventBridge also supports event schema registry, event scheduling, and event pipes for one-to-one integration pipelines.

Key Concepts in Serverless Development:

When building serverless microservices, it is essential to understand key architectural concepts and design patterns. These include two-tier and three-tier client-server architectures, API-first thinking, modular systems, and the principles of hexagonal architecture, onion architecture, clean architecture, and MACH architecture. Each of these concepts contributes to the overall design and maintainability of serverless applications.

Identifying Set Pieces and Event Categories:

To effectively design serverless microservices, it is important to identify set pieces and event categories. Set pieces can be broken down into subdomains, synchronous and asynchronous interactions, external interactions, administrative activities, push notifications, common resources, logs streaming, fraud prevention, and more. Event categories, on the other hand, help classify events based on their origin, boundary, and ownership. Common event types include commands, data events, queries, requests, responses, status events, and tasks.

Architectural Considerations for Event Sourcing:

Event sourcing is an important pattern and practice in serverless development. When implementing event sourcing, it is crucial to address challenges such as identifying which events to keep in an event store, collecting related events, determining the scope of event stores, handling sensitive data, and defining data retention policies. A dedicated microservice for event sourcing can help manage these challenges and ensure the proper handling of events.

Domain Experts and EventStorming:

Domain experts play a vital role in the development process, especially during events like EventStorming workshops. Domain-level EventStorming helps identify business processes, domain events, commands, actors, and aggregates, while development-level EventStorming focuses on smaller-scale activities involving the engineering team, stakeholders, product managers, and UX designers. These workshops facilitate collaboration and knowledge sharing, ensuring that the serverless architecture aligns with the business domain.

Conclusion:

Building serverless microservices with a clean architecture and domain-driven design requires a deep understanding of event-driven architecture, event routing, and the features of services like AWS EventBridge. By following best practices and utilizing tools like EventStorming, developers can create robust and scalable serverless applications.

Actionable Advice:

  1. Embrace event-driven architecture and use AWS EventBridge as a central event router for your serverless microservices.
  2. Apply domain-driven design principles to organize your codebase, focusing on aggregates, entities, and clean architecture.
  3. Consider implementing event sourcing for auditing and tracing critical business flows, and utilize dedicated microservices for event sourcing tasks.

By combining these concepts and practices, developers can build serverless applications that are scalable, maintainable, and aligned with business requirements.

Sources

← Back to Library

Hatch New Ideas with Glasp AI 🐣

Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)

Start Hatching 🐣