Skip to content

Add Akka.NET containers for SAGA management in event sourcing microservices#5

Merged
MoimHossain merged 1 commit intomasterfrom
copilot/fix-1
Aug 26, 2025
Merged

Add Akka.NET containers for SAGA management in event sourcing microservices#5
MoimHossain merged 1 commit intomasterfrom
copilot/fix-1

Conversation

Copy link
Contributor

Copilot AI commented Aug 26, 2025

This PR implements a comprehensive SAGA pattern solution using Akka.NET actors for managing distributed transactions in the microservice architecture, addressing the need for reliable event sourcing capabilities.

What's New

Core SAGA Infrastructure

  • SagaCoordinatorActor: Manages individual SAGA lifecycles with state transitions and compensation logic
  • EisenSagaActor: Handles business logic for Eisen (project/requirement) creation with a 3-step workflow
  • SagaManagerActor: Coordinates multiple SAGA instances across the system
  • Message System: Complete set of command/event messages for SAGA coordination

API Enhancements

The EisenController now supports SAGA-based operations:

# Create an Eisen with SAGA coordination
POST /api/eisen
{
  "Title": "Quantum Computer",
  "Description": "Build a universal quantum computer",
  "Phase": "Research ontwerp"
}

# Track SAGA progress
GET /api/eisen/saga/{sagaId}/status

# Monitor active SAGAs
GET /api/eisen/sagas/count

SAGA Workflow Example

For Eisen creation, the SAGA executes these compensatable steps:

  1. Validation: Validates input data
  2. Persistence: Saves to database (simulated)
  3. Notification: Sends external notifications (simulated)

If any step fails, automatic compensation rolls back completed steps in reverse order.

Technical Details

Architecture Updates

  • Upgraded from .NET Core 1.0 to .NET 8.0 for modern framework support
  • Integrated Akka.NET 1.5.13 with cluster-ready configuration
  • Implemented choreography-based SAGA pattern for loose coupling
  • Added comprehensive error handling and compensation logic

Key Benefits

  • Reliability: Akka.NET supervision strategies ensure fault tolerance
  • Scalability: Actor-based design supports horizontal scaling
  • Observability: Built-in logging shows SAGA execution flow
  • Maintainability: Clear separation of concerns between SAGA steps

Configuration

The ActorSystem is configured in Startup.cs with proper dependency injection:

var actorSystem = ActorSystem.Create("SagaSystem", akkaConfig);
services.AddSingleton(actorSystem);
services.AddSingleton<ISagaService, SagaService>();

Testing

All endpoints have been tested and verified:

  • SAGA creation and execution work correctly
  • Status tracking provides real-time updates
  • Actor message flow is properly logged
  • Compensation logic is ready for failure scenarios

This implementation provides a solid foundation for distributed transaction management and event sourcing in the microservice tutorial, demonstrating how actor models can effectively manage complex business workflows.

Fixes #1.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Contributor Author

Copilot AI commented Aug 26, 2025

@MoimHossain 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@MoimHossain MoimHossain marked this pull request as ready for review August 26, 2025 06:39
@MoimHossain MoimHossain merged commit 7de17e1 into master Aug 26, 2025
1 check passed
Copilot AI changed the title [WIP] Add Akka.net containers for SAGA management Add Akka.NET containers for SAGA management in event sourcing microservices Aug 26, 2025
Copilot AI requested a review from MoimHossain August 26, 2025 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Akka.net containers for SAGA management

2 participants