Microservices and Hexagonal Architecture
A five-day training on designing and building microservices with Python. From architecture principles and domain-driven design to production infrastructure and advanced distributed patterns.
Duration
5 days (35 hours)
Format
50 percent presentation, 50 percent exercises
Prerequisites
Solid Python fundamentals required, web development experience recommended
Materials
Virtual machines provided, electronic course materials
Day 1 — Architecture Principles
Monolith vs Microservices
- Monolithic architecture: strengths, limitations, when it breaks down
- Microservices: benefits, costs, when to split
- The spectrum: modular monolith, macro-services, micro-services
Hexagonal Architecture
- Ports and adapters: separating business logic from infrastructure
- Dependency inversion: pointing dependencies inward
- Clean architecture patterns: entities, use cases, interfaces
Domain-Driven Design Basics
- Ubiquitous language and bounded contexts
- Entities, value objects, and aggregates
- Domain events and domain services
Day 2 — Service Design
Bounded Contexts and API Contracts
- Defining service boundaries from business domains
- API contracts: OpenAPI, protocol buffers, consumer-driven contracts
- Versioning strategies: URL versioning, header versioning, backward compatibility
Event-Driven Communication
- Message brokers: RabbitMQ concepts, exchanges, queues, routing
- Apache Kafka concepts: topics, partitions, consumer groups
- CQRS pattern: separating read and write models
- Event sourcing: storing state as a sequence of events
Day 3 — Implementation with Python
Service Skeleton
- Project structure for a hexagonal microservice
- Dependency injection with Python: manual injection, inject library
- Repository pattern: abstracting data access
- Unit of work pattern: managing transactions
Inter-Service Communication
- REST: synchronous HTTP calls between services
- gRPC: protocol buffers, service definitions, Python stubs
- Async messaging: publishing and consuming events
- Service discovery: registry patterns, DNS-based discovery
Day 4 — Infrastructure
Containerization and Orchestration
- Docker Compose for local development: multi-service setups
- Kubernetes basics: pods, deployments, services, config maps
- CI/CD for microservices: independent deployment pipelines
Observability
- Structured logging: correlation IDs, log aggregation
- Metrics: Prometheus, counters, histograms, dashboards
- Distributed tracing: OpenTelemetry, Jaeger
Resilience
- Health checks: liveness probes, readiness probes
- Resilience patterns: retries, timeouts, bulkheads
- Graceful degradation and fallback strategies
Day 5 — Advanced Patterns and Project
Advanced Patterns
- Saga pattern: orchestration vs choreography for distributed transactions
- Circuit breaker: preventing cascade failures
- Outbox pattern: reliable event publishing with database transactions
- API Gateway patterns: routing, authentication, rate limiting
Testing Strategies
- Unit testing hexagonal services: mocking ports and adapters
- Integration testing: testing with real databases and message brokers
- Contract testing: ensuring API compatibility between services
- End-to-end testing: testing the full system
Migration and Project
- Migrating from monolith: strangler fig pattern, incremental extraction
- Practical project: designing and implementing a multi-service system
