Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: kick-off event sourced tasks-svc #587

Merged
merged 75 commits into from
Jan 25, 2024
Merged

Conversation

MaxSchaefer
Copy link
Member

@MaxSchaefer MaxSchaefer commented Dec 20, 2023

This pull request starts our journey towards event sourcing and domain-driven-design in general. Therefore I've implemented libs/hwes that gets consumed by tasks-svc (and every other service that wants to utilizing event sourcing). libs/hwes introduces the concepts of Commands, Events, Aggregates and Aggregates stores. These concepts are implemented by tasks-svc, for example TaskAggregate or CreateTaskCommand or TaskCreatedEvent.

We already did a meeting on this new architecture but here is an outline:

  1. Request gets handled by command or query (cq)
  2. CQ loads the aggregate on which behalf to act on (by ID of aggregate)
    2.1 Create empty aggregate by the passed ID
    2.2 Load all events from the event store for that aggregate (every aggregate has its own event stream)
    2.3 Applying all events in order on the aggregate
  3. CQ triggers business logic on aggregates that resolves in new uncommitted events
  4. Before returning the request back to the caller of the CQ, persist all events in our event store.
    4.1 libs/hwes calculates the expected revision of the targeted event stream by combining the applied events of step 2. and the uncommitted events of step 3. .
    4.2.a If the revision cannot be reached due to concurrent changes to the targeted event stream the request fails.
    4.2.b If the revision can be reached during persistence, the events got stored successfully.

Step 4.2 describes optimistic concurrency. The application needs to keep track of versioning. We could apply all events, regarding there version but this can result in data conflicts and issues with idempotency. Its quite unlikely that Step 4.2.a occur but we need to keep track of this architecture trade-off with future metrics and tracing.

tasks-svc is not yet production ready. We can either integrate the event sourced task domain into the current task-svc or the other way around. Upcoming issues will work towards the production readiness.

To-dos for later issues

  • Snapshots
  • Projections and Subscriptions
  • Identity context in events

Also closes #344

@MaxSchaefer MaxSchaefer self-assigned this Dec 20, 2023
@MaxSchaefer MaxSchaefer force-pushed the issue/x-cqrs-es-arch branch 3 times, most recently from 8eba2f4 to 4803a8e Compare December 29, 2023 22:41
@MaxSchaefer MaxSchaefer requested a review from FoseFx January 17, 2024 23:08
libs/hwes/aggregate.go Outdated Show resolved Hide resolved
libs/hwes/aggregate.go Outdated Show resolved Hide resolved
libs/hwes/aggregate.go Show resolved Hide resolved
libs/hwes/event.go Outdated Show resolved Hide resolved
libs/hwes/eventstoredb/setup.go Show resolved Hide resolved
services/tasks-svc/internal/task/aggregate/actions.go Outdated Show resolved Hide resolved
services/tasks-svc/internal/task/aggregate/aggregate.go Outdated Show resolved Hide resolved
@MaxSchaefer MaxSchaefer requested a review from FoseFx January 22, 2024 20:17
Copy link
Member

@FoseFx FoseFx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥂

@MaxSchaefer MaxSchaefer changed the title feat: event sourced tasks-svc feat: kick-off event sourced tasks-svc Jan 25, 2024
@MaxSchaefer MaxSchaefer merged commit 6160451 into main Jan 25, 2024
42 checks passed
@FoseFx FoseFx deleted the issue/x-cqrs-es-arch branch September 13, 2024 16:22
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.

Rename task-svc to tasks-svc
3 participants