Implement outbox pattern for reliable event publishing in Products microservice#48
Closed
Copilot wants to merge 4 commits into
Closed
Implement outbox pattern for reliable event publishing in Products microservice#48Copilot wants to merge 4 commits into
Copilot wants to merge 4 commits into
Conversation
Co-authored-by: ElectNewt <1971861+ElectNewt@users.noreply.github.com>
Co-authored-by: ElectNewt <1971861+ElectNewt@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement outbox pattern in the Prodcuts microservice
Implement outbox pattern for reliable event publishing in Products microservice
Jun 30, 2025
ElectNewt
reviewed
Jun 30, 2025
|
|
||
| private class ProductDetailEntity | ||
|
|
||
| public async Task AddOutboxMessage(string eventType, object eventData, string routingKey) |
Author
There was a problem hiding this comment.
You're right, I've removed the unused AddOutboxMessage method. The use cases now only use CreateRecordWithOutboxMessage and UpdateProductWithOutboxMessage methods which handle the outbox pattern transactionally. Fixed in commit e4b89ec.
| Task MarkAsFailed(int messageId, string errorMessage); | ||
| } | ||
|
|
||
| public class OutboxRepository : IOutboxRepository |
Owner
There was a problem hiding this comment.
this is an indirection layer that it is not needed
Author
There was a problem hiding this comment.
Agreed, I've removed the OutboxRepository indirection layer and moved the outbox operations directly to ProductsWriteStore. OutboxProcessor now depends on IProductsWriteStore directly, simplifying the architecture while maintaining the same functionality. Fixed in commit e4b89ec.
Co-authored-by: ElectNewt <1971861+ElectNewt@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements the outbox pattern to ensure reliable event publishing when products are created or updated, addressing the critical requirement for guaranteed event propagation in the Products microservice.
Problem
Previously, product events were published directly to the message broker after database operations, creating a risk of lost events if the message broker was unavailable or if failures occurred between database commits and message publishing.
Solution
Implemented the outbox pattern with the following components:
🗃️ Database Changes
OutboxMessagestable to store pending events atomically with product operations🔄 Core Components
📝 Updated Use Cases
CreateProductDetails: Now stores events in outbox instead of direct publishingUpdateProductDetails: Same transactional approach for update events✅ Testing
Benefits
Example Usage
The API contracts remain unchanged - the outbox pattern works transparently:
Configuration
The background service is automatically registered in dependency injection:
Fixes #45.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.