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

Allow to configure stream name in aggregate #658

Merged
merged 7 commits into from
Dec 20, 2024
Merged

Conversation

DavidBadura
Copy link
Member

@DavidBadura DavidBadura commented Dec 14, 2024

In the new stream store, the events are stored in streams. Previously, the stream was structured as follows: {aggregateName}-{aggregateId}. You can now configure this yourself using the attribute stream. {id} is a placeholder that can be used for the aggregate ID.

use Patchlevel\EventSourcing\Aggregate\BasicAggregateRoot;
use Patchlevel\EventSourcing\Attribute\Aggregate;
use Patchlevel\EventSourcing\Attribute\Stream;

#[Aggregate('profile')]
#[Stream('profile-{id}')]
final class Profile extends BasicAggregateRoot
{
    // ...
}

You can also use the same stream as another aggregate. This would cause both aggregates to read and write to the same stream. This is useful if you want to use the Micro Aggregates pattern. The ability to specify an aggregate to say you want to use its stream has also been added for DX.

use Patchlevel\EventSourcing\Aggregate\BasicAggregateRoot;
use Patchlevel\EventSourcing\Attribute\Aggregate;

#[Aggregate('guest_list')]
#[Stream(Meeting::class)]
final class GuestList extends BasicAggregateRoot
{
    // ...
}

Copy link

github-actions bot commented Dec 14, 2024

Hello 👋

here is the most recent benchmark result:

SimpleSetupBench
================

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 974.500μs (±0.00%) | 987.700μs (±0.00%) | -1.34%    | 34.266mb        | 34.274mb   | -0.02%      |
| benchLoad10000Events ()                | 49.754ms (±0.00%)  | 48.686ms (±0.00%)  | +2.19%    | 34.266mb        | 34.274mb   | -0.02%      |
| benchSave1Event ()                     | 1.000ms (±0.00%)   | 1.091ms (±0.00%)   | -8.26%    | 33.765mb        | 33.765mb   | +0.00%      |
| benchSave10000Events ()                | 222.830ms (±0.00%) | 227.142ms (±0.00%) | -1.90%    | 33.765mb        | 33.765mb   | +0.00%      |
| benchSave10000Aggregates ()            | 8.250s (±0.00%)    | 8.778s (±0.00%)    | -6.01%    | 33.765mb        | 33.765mb   | +0.00%      |
| benchSave10000AggregatesTransaction () | 4.909s (±0.00%)    | 4.909s (±0.00%)    | -0.01%    | 33.765mb        | 33.765mb   | +0.00%      |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

SnapshotsBench
==============

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad10000EventsMissingSnapshot () | 49.032ms (±0.00%)  | 49.839ms (±0.00%)  | -1.62%    | 33.836mb        | 33.836mb   | +0.00%      |
| benchLoad10000Events ()                | 914.500μs (±0.00%) | 934.700μs (±0.00%) | -2.16%    | 33.836mb        | 33.836mb   | +0.00%      |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

SubscriptionEngineBatchBench
============================

+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
|                           | time (kde mode)                                   | memory                                     |
+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
| subject                   | Tag: <current>    | Tag: base         | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
| benchHandle10000Events () | 74.995ms (±0.00%) | 74.764ms (±0.00%) | +0.31%    | 34.234mb        | 34.234mb   | +0.00%      |
+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+

SubscriptionEngineBench
=======================

+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
|                           | time (kde mode)                               | memory                                     |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
| subject                   | Tag: <current>  | Tag: base       | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
| benchHandle10000Events () | 3.196s (±0.00%) | 3.195s (±0.00%) | +0.06%    | 46.382mb        | 46.382mb   | +0.00%      |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+

PersonalDataBench
=================

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 912.200μs (±0.00%) | 918.200μs (±0.00%) | -0.65%    | 34.895mb        | 34.895mb   | +0.00%      |
| benchLoad10000Events ()                | 85.821ms (±0.00%)  | 88.221ms (±0.00%)  | -2.72%    | 34.895mb        | 34.895mb   | +0.00%      |
| benchSave1Event ()                     | 1.581ms (±0.00%)   | 1.554ms (±0.00%)   | +1.71%    | 34.895mb        | 34.895mb   | +0.00%      |
| benchSave10000Events ()                | 250.544ms (±0.00%) | 253.550ms (±0.00%) | -1.19%    | 34.897mb        | 34.897mb   | +0.00%      |
| benchSave10000Aggregates ()            | 12.596s (±0.00%)   | 12.551s (±0.00%)   | +0.36%    | 34.895mb        | 34.895mb   | +0.00%      |
| benchSave10000AggregatesTransaction () | 9.160s (±0.00%)    | 9.151s (±0.00%)    | +0.09%    | 35.396mb        | 35.396mb   | +0.00%      |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

SimpleSetupStreamStoreBench
===========================

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 998.600μs (±0.00%) | 1.018ms (±0.00%)   | -1.92%    | 34.862mb        | 34.862mb   | -0.00%      |
| benchLoad10000Events ()                | 55.190ms (±0.00%)  | 55.389ms (±0.00%)  | -0.36%    | 34.862mb        | 34.862mb   | -0.00%      |
| benchSave1Event ()                     | 1.232ms (±0.00%)   | 1.067ms (±0.00%)   | +15.48%   | 34.862mb        | 34.862mb   | -0.00%      |
| benchSave10000Events ()                | 303.299ms (±0.00%) | 305.471ms (±0.00%) | -0.71%    | 34.862mb        | 34.862mb   | -0.00%      |
| benchSave10000Aggregates ()            | 8.551s (±0.00%)    | 8.656s (±0.00%)    | -1.21%    | 34.862mb        | 34.862mb   | -0.00%      |
| benchSave10000AggregatesTransaction () | 5.183s (±0.00%)    | 5.164s (±0.00%)    | +0.38%    | 34.862mb        | 34.862mb   | -0.00%      |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

SplitStreamBench
================

+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                         | time (kde mode)                                     | memory                                     |
+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                 | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad10000Events () | 4.448ms (±0.00%)   | 4.338ms (±0.00%)   | +2.54%    | 37.072mb        | 37.072mb   | +0.00%      |
| benchSave10000Events () | 355.711ms (±0.00%) | 348.214ms (±0.00%) | +2.15%    | 37.144mb        | 37.144mb   | +0.00%      |
+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

This comment gets update everytime a new commit comes in!

@DavidBadura DavidBadura changed the base branch from 3.6.x to 3.7.x December 18, 2024 10:48
@DavidBadura DavidBadura changed the title POC replace child aggregates with micro aggregates Allow to configure stream name Dec 18, 2024
@DavidBadura DavidBadura marked this pull request as ready for review December 18, 2024 13:45
@DavidBadura DavidBadura added the enhancement New feature or request label Dec 18, 2024
@DavidBadura DavidBadura added this to the 3.7.0 milestone Dec 18, 2024
@DavidBadura DavidBadura changed the title Allow to configure stream name Allow to configure stream name in aggregate Dec 18, 2024
@DavidBadura DavidBadura merged commit 669b62f into 3.7.x Dec 20, 2024
39 of 40 checks passed
@DanielBadura DanielBadura deleted the micro-aggregates branch December 20, 2024 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants