TaskGo-Platform - Advanced Microservices Reference
Overview
This repository serves as a comprehensive learning and example project for the TaskGo-Platform microservices implementation. It demonstrates advanced production-ready patterns including hexagonal architecture, domain-driven design, event-driven architecture, and transactional outbox patterns for building robust microservices using Spring Boot.
Why "TaskGo-Platform"?
This project goes beyond basic microservices implementation to provide a complete backend platform that includes:
- Infrastructure Foundation: Rate limiting, caching, observability, and monitoring
- Production Patterns: Transactional outbox, event replay, and admin tooling
- Advanced Architecture: Hexagonal design with clean separation of concerns
- Enterprise Features: Distributed tracing, metrics, and health monitoring
- Developer Experience: Comprehensive API documentation and debugging tools
The "Platform" designation reflects that this isn't just a collection of services, but a complete, production-ready foundation for building scalable microservices applications.
Architecture Diagram
[ Client / Frontend ]
|
v
[ API Gateway ]
|
-----------------------------------------
| | |
v v v
[ Task Service ] [ User Service ] [ Notification Service ]
| | |
| | |
| | |
| | |
----------- Service Communication ------------
|
[ Auth Service ]
|
[ Database(s) ]
### How to Read This Diagram
- **Client / Frontend:** Your app or UI sends all requests through the API Gateway.
- **API Gateway:** Routes requests to the correct microservice, handles load balancing, and enforces security.
- **Task Service:** Manages tasks (CRUD, completion, deadlines).
- **User Service:** Manages users and their profiles.
- **Notification Service:** Sends reminders or updates asynchronously.
- **Auth Service:** Handles login, JWT tokens, and user authentication.
- **Databases:** Each service can have its own database (recommended), or start with one shared DB for learning.
## Microservice Breakdown
### Task Service
- **Architecture**: Hexagonal Architecture (Ports and Adapters) with Domain-Driven Design
- **Technologies**: Java 21, Spring Boot 3.4.1, Spring Data JPA, RabbitMQ, H2 Database
- **Features**: CRUD operations, event-driven architecture, transactional outbox pattern, admin endpoints
**Core Endpoints**:
- `POST /api/v1/tasks` - Create new task
- `PUT /api/v1/tasks/{id}` - Update existing task
- `GET /api/v1/tasks` - List tasks with filtering and pagination
- `DELETE /api/v1/tasks/{id}` - Delete task
**Admin Endpoints**:
- `POST /api/v1/admin/outbox/replay/failed` - Replay failed events
- `POST /api/v1/admin/outbox/replay/{id}` - Replay specific event
- `POST /api/v1/admin/outbox/replay/reset/{id}` - Reset retry count
- `POST /api/v1/admin/outbox/replay/date-range` - Replay events by date range
- `GET /api/v1/admin/outbox/status` - Get outbox status
- `GET /api/v1/admin/outbox/events` - List outbox events
**Advanced Features**:
- Event-driven architecture with RabbitMQ integration
- Transactional outbox pattern for reliable event publishing
- Domain events: TaskCreatedEvent, TaskUpdatedEvent, TaskDeletedEvent
- Automatic retry with exponential backoff (max 3 attempts)
- Rate limiting with Bucket4j
- Caching with Caffeine
- Distributed tracing with OpenTelemetry
- Metrics with Micrometer and Prometheus
- API documentation with Swagger/OpenAPI
### User Service
- Manage users and profiles
- Endpoints: ``/users``, ``/users/{id}/tasks``
### Notification Service
- Send reminders or updates
- Endpoints: ``/notifications/send``, ``/notifications/{taskId}``
### API Gateway
- Entry point for clients
- Routes requests to services
- Handles load balancing and security
### Auth Service
- JWT/OAuth2 authentication
- Endpoints: ``/auth/login``, ``/auth/register``
### Databases
- Each service can have its own DB (recommended)
- For learning, start with one shared DB
## Learning Path
1. Start with Task Service + User Service (REST controllers, repositories).
2. Add API Gateway for routing.
3. Introduce communication between services.
4. Containerize with Docker.
5. Add Notification Service with async messaging.
6. Secure with JWT authentication.
Example Controller (Task Service - CreateTaskController)
```java
@RestController
@RequestMapping("/api/v1/tasks")
@Tag(name = "Task Command", description = "Operations to create and update tasks")
public class CreateTaskController {
private final CreateTaskHandler createTaskHandler;
public CreateTaskController(CreateTaskHandler createTaskHandler) {
this.createTaskHandler = createTaskHandler;
}
@PostMapping
@Operation(summary = "Create a new task")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void create(@Valid @RequestBody CreateTaskRequestDto dto) {
createTaskHandler.handle(dto);
}
}
Example Application Service (Task Service - CreateTaskHandler)
@Service
public class CreateTaskHandler {
private final TaskWriteRepository taskWriteRepository;
private final UserValidationPort userValidationPort;
private final TaskCreatedPublisherPort taskCreatedPublisherPort;
public CreateTaskHandler(TaskWriteRepository taskWriteRepository,
UserValidationPort userValidationPort,
TaskCreatedPublisherPort taskCreatedPublisherPort) {
this.taskWriteRepository = taskWriteRepository;
this.userValidationPort = userValidationPort;
this.taskCreatedPublisherPort = taskCreatedPublisherPort;
}
public void handle(CreateTaskRequestDto dto) {
// Validate user exists
userValidationPort.validateUserExists(dto.getUserId());
// Create task using domain service
CreateTaskCommand command = new CreateTaskCommand(
dto.getTitle(), dto.getDescription(), dto.getPriority(),
dto.getProject(), dto.getUserId()
);
Task task = new Task(command);
taskWriteRepository.save(task);
// Publish domain event
TaskCreatedEvent event = new TaskCreatedEventV1(task);
taskCreatedPublisherPort.publish(event);
}
}
Key Learning Concepts
-
Hexagonal Architecture: Clean separation between domain logic and infrastructure through ports and adapters.
-
Domain-Driven Design (DDD): Rich domain models with business logic encapsulated in entities and value objects.
-
Spring Boot REST Controllers: Each microservice exposes its own REST API with proper validation and error handling.
-
Spring Data JPA: Simplify repositories for persistence with custom query methods and specifications.
-
Event-Driven Architecture: Use domain events and RabbitMQ for asynchronous communication between services.
-
Transactional Outbox Pattern: Ensure reliable event publishing within database transactions.
-
API Gateway: Central routing, load balancing, and security.
-
Configuration Management: Spring Cloud Config for shared configs.
-
Service Discovery: Eureka or Consul to register and discover services.
-
Containerization: Package each microservice in Docker for isolation.
-
Observability: Add logging, metrics (Micrometer + Prometheus), and distributed tracing (OpenTelemetry).
-
Rate Limiting: Implement rate limiting with Bucket4j to protect your services.
-
Caching: Use Caffeine for in-memory caching to improve performance.
Coding Practices
-
Hexagonal Architecture: Keep strict separation between domain, application, and infrastructure layers. Use ports (interfaces) to define contracts and adapters for implementations.
-
Domain-Driven Design: Model business concepts as rich entities with behavior, use value objects for concepts without identity, and apply domain services for complex business logic.
-
Command Query Responsibility Segregation (CQRS): Separate read and write operations with different controllers and handlers for better scalability and maintainability.
-
DTOs & Validation: Use dedicated DTOs for API requests/responses with proper validation annotations. This prevents leaking domain model details and ensures data integrity.
-
Event-First Design: Design domain events first to capture business state changes, then implement the command handlers that publish these events.
-
Transactional Boundaries: Keep transactions at the application service level and use the outbox pattern for reliable event publishing.
-
Error Handling: Implement domain-specific exceptions and use @ControllerAdvice for consistent error responses across all endpoints.
-
API Documentation: Use OpenAPI/Swagger annotations to automatically generate comprehensive API documentation.
Security & Observability
-
JWT Authentication: Add a simple Auth service to practice Spring Security and protect endpoints.
-
Metrics & Monitoring: Use Micrometer + Prometheus for comprehensive metrics collection and Grafana for visualization.
-
Distributed Tracing: Integrate OpenTelemetry with Zipkin export to trace requests across service boundaries.
-
Health Checks: Use Spring Boot Actuator endpoints for health monitoring and service discovery.
-
Rate Limiting: Implement Bucket4j-based rate limiting to protect services from abuse and ensure fair usage.
-
Caching: Leverage Caffeine for high-performance in-memory caching to reduce database load.
-
Event Monitoring: Monitor outbox table status and event publishing success rates through dedicated admin endpoints.
Learning Milestones
-
Milestone 1: Build Task Service with CRUD endpoints and persistence. ✅
-
Milestone 2: Add User Service and make Task Service validate task ownership.
-
Milestone 3: Introduce API Gateway and route traffic.
-
Milestone 4: Add Notification Service with async messaging (RabbitMQ/Kafka).
-
Milestone 5: Secure everything with JWT.
-
Milestone 6: Containerize with Docker Compose and run all services together.
Learning Mindset
-
Treat each service as a mini‑project: document endpoints, DB schema, and decisions.
-
Keep reference diagrams updated as you expand.
-
Practice manual scaffolding first — it builds intuition before you experiment with generators.
This repository is designed to guide you step-by-step through building and understanding a microservices architecture with practical examples and clear explanations. Feel free to explore, modify, and expand the code as you learn.