event-sourcing

 by   goodby PHP Version: Current License: MIT

kandi X-RAY | event-sourcing Summary

kandi X-RAY | event-sourcing Summary

event-sourcing is a PHP library. event-sourcing has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

event-sourcing
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              event-sourcing has a low active ecosystem.
              It has 16 star(s) with 0 fork(s). There are 4 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 1 open issues and 0 have been closed. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of event-sourcing is current.

            kandi-Quality Quality

              event-sourcing has 0 bugs and 0 code smells.

            kandi-Security Security

              event-sourcing has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              event-sourcing code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              event-sourcing is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              event-sourcing releases are not available. You will need to build from source code and install.
              Installation instructions, examples and code snippets are available.
              event-sourcing saves you 225 person hours of effort in developing the same functionality from scratch.
              It has 550 lines of code, 60 functions and 16 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed event-sourcing and discovered the below as its top functions. This is intended to give you an instant insight into event-sourcing implemented functionality, and help decide if they suit your requirements.
            • Appends one or more events to an event stream .
            • Set the last dispatched event id
            • Get the last error message
            • Creates an exception for the event stream .
            • Creates an exception for the event stream .
            • Get the contract data .
            • Creates an exception for the last dispatched event .
            • Show new events .
            • Get the event id .
            • Get the name of the stream .
            Get all kandi verified functions for this library.

            event-sourcing Key Features

            No Key Features are available at this moment for event-sourcing.

            event-sourcing Examples and Code Snippets

            No Code Snippets are available at this moment for event-sourcing.

            Community Discussions

            QUESTION

            CQRS with event driven architecture but without event sourcing
            Asked 2021-May-11 at 14:43

            Before posting this, I referred many sites and learning platforms but saw similar pattern of developing CQRS with event sourcing. Again to have proper events you need to follow DDD pattern. I have below questions.

            1. Can we keep read and write DB in sync just by publishing event from write model and consume it at read model using event handler and updating read database
            2. Why Event-Sourcing and replay of events needed if my requirement is to only see latest data
            3. I can manage audit of data as and when events reaches at event handler
            4. I can version messages based on timestamp in case if race condition.
            5. Please explain by doing steps 1,3 and 4, am I still following CQRS pattern?

            FYI, I am using .NetCore 3.1, AWS Lambda services, MassTransit as a MessageBus and SQS as a transport.

            Thanks in advance.

            ...

            ANSWER

            Answered 2021-May-11 at 14:30

            As soon as you have separate data models for reading and writing, you're following CQRS. Event sourcing is not strictly required.

            Note that accomplishing 1 in an application in a way which preserves the expected eventual consistency of the read side with the write side is rather difficult. You'll need to ensure that you publish the event if and only if the update of the write DB succeeded (i.e. there's never a case where you publish and don't update nor is there ever a case where you update but don't publish: if either of those could happen, you cannot guarantee eventual consistency). For instance, if your application does the update and if that succeeds, publishes the event, what happens if the process crashes (or you get network partitioned from the DB, or your lambda exceeds its time limit...) between the update and publishing?

            The 2 best ways to ensure eventual consistency are to

            • update the write side DB by subscribing to the published event stream
            • use change data capture on the write side DB to generate events to publish

            The first is at least very close to event sourcing (one could argue either way: I'd say that it depends on the extent to which your design considers the published event stream the source of truth). In the second, remember that you've basically lost all the contextual domain knowledge around the what's happened around that event: you're only seeing what changed in the DB's representation of the model.

            Event sourcing and CQRS mutually improve each other (you can event source without doing CQRS, too, though it's only in certain applications that ES without CQRS is practical); event sourcing tends to let you keep the domain front-and-center and since it's append-only, it's the most optimized write model you can have.

            Source https://stackoverflow.com/questions/67487981

            QUESTION

            Event sourcing and Domain Event
            Asked 2021-May-11 at 03:53

            What is Event sourcing and what is Domain Event.

            I read both the articles and I am not be able to get it properly. So, please describe it in easy words.

            And what is the difference between them?

            Are domain events and event driven are same?

            ...

            ANSWER

            Answered 2021-May-02 at 13:46

            Not your fault: the literature is a mess.

            Domain events, event sourcing, and event driven are three different ideas that happen to share the label "event".

            Domain events are a domain modeling pattern; in effect making "things that happen" a first class citizen in your domain model. Think BookSold, not MouseClicked

            Event sourcing is a data modeling pattern; instead of having a domain entity with mutable properties, we have a domain entity with a history of changes.

            Event driven is a communication pattern; system A publishes an event, and system B reacts. Notice that system A and system B don't even need to know about each other; the only need a common undertanding of the event, and shared plumbing (aka middleware).

            Source https://stackoverflow.com/questions/67356709

            QUESTION

            Event Sourcing and cqrs with eventstore db
            Asked 2021-Mar-16 at 15:59

            store db and event-sourcing, but I have doubts regarding projections and cqrs. So far this is the way in which I call my commando and my command handler:

            create-user-command

            ...

            ANSWER

            Answered 2021-Mar-16 at 15:59

            In CQRS, when using EventStoreDb, your aggregate must be designed to be restored to a state from Events. Events are stored in a stream with a unique name and identifier (guid). When modifying the aggregate, you must read this stream, and apply each event in sequence to restore the current state, before executing any changes to the aggregate (which generates more events). In order to maintain integrity and handle optimistic concurrency, you should have a simple version check in your aggregate which counts the old events + new events to ascertain to latest version number to be persisted.

            The issues I see above are as follows. Your aggregate has a constructor and a static method which generates events without any validation of the current state i.e.: What happens if I call create twice with the same guid?

            this.apply(new UserCreatedEvent(guid, {email, name}, new Date()));

            You are applying state here directly. Instead, you should raise the event inside your Create method.

            this.raiseEvent(new UserCreatedEvent(guid, {email, name}, new Date()));

            This should be implemented to do the following.

            • Added to a list of uncommitted events
            • this.apply called

            You should then persist the events to the EventStoreDb in your command handler.

            Source https://stackoverflow.com/questions/66614827

            QUESTION

            How to implement Event sourcing and a database in a microservice architecture?
            Asked 2021-Feb-02 at 04:18

            I have been learning lately about microservices architecture and it's features. in this source it appears that event sourcing is replacing a database, however, it is later stated:

            The event store is difficult to query since it requires typical queries to reconstruct the state of the business entities. That is likely to be complex and inefficient. As a result, the application must use Command Query Responsibility Segregation (CQRS) to implement queries.

            In the CQRS Page the author seems to describe a singular database that listens to all events and reconstructs itself.

            My question(s) is:

            What is actually needed to implement event sourcing with a queryable database? particularly:

            Where is the events database? Where is the queryable database? Do I need to have multiple event stores for every service or can I store events in a message broker like Kafka? is the CQRS database actually is one "whole" database that collects all the events? And how can all of this scale?

            I'm sorry if I'm not clear with my question, I am very confused myself. I guess I'm looking for a full example architecture of how things will look in the grand picture.

            ...

            ANSWER

            Answered 2021-Feb-02 at 03:50

            Event Source is not replacing the DB. It has some benefits and challenges. So, we should choose it wisely. If you are not comfortable then don't choose it. You can implement Microservice Style without event sourcing.

            Query able DB - Simple solution is to implement CQRS pattern and keep your Query DB in sync with Event Source DB.

            Event DB should be with owner service like if you are keeping events about Order than it should be in Order service. (Yeah, other service can have replica of the same).

            You may use Kafka as intermediate storage for event but not the final one.

            CQRS is not about one DB. It an pattern where we use to DB models, one is for Command and Another one is for Query.

            If you understand Java then please refer Book "Microservice Patterns - Chris Richardson" and if you are from C# or Microsoft technology stack then you may refer "https://github.com/dotnet-architecture/eShopOnAzure".

            Source https://stackoverflow.com/questions/66000270

            QUESTION

            Is Command Handler is just receiving commands from the bus and publish the event?
            Asked 2021-Jan-30 at 14:56

            I am actually new in CQRS and Event Sourcing.

            I got confused by Command Handler in Aggregate, when i saw this code :

            ...

            ANSWER

            Answered 2021-Jan-30 at 13:16

            You are mixing some concepts. Let's clarify them.

            Event Sourcing

            If you implement event sourcing, it means that your source of truth is the events themselves. You store events, not a concrete "state" (an entity). Let's see some pseudo-code:

            To create a new account:

            Source https://stackoverflow.com/questions/65967849

            QUESTION

            NestJs EventBus duplicates event at EventHandler
            Asked 2020-Oct-15 at 08:38

            I am trying out Event-Sourcing and CQRS using NestJs using Kafka as the Event Store.

            The application is a small and simple one having 2 parts, customer and order. You first create a customer with some initial balance and then using the customer id you create an order, if the amount of the order is less than balance then it is approved otherwise rejected.

            Here is the code in question: https://github.com/Ashniu123/nestjs-customer-order-eventsourcing-cqrs

            I use KafkaJs as the EventBus (created my own KafkaModule under libs/)

            When I run this with Kafka and MongoDB, the app starts up just fine. And when I create a customer too, the event CreateCustomerEvent is published as expected and pushed onto Kafka by the CommandHandler. (Checked using the landoop UI)

            The problem comes in when the Event is read from Kafka and pushed onto the EventBus to be picked up and executed by the EventHandler. Like CreateCustomerEventHandler.

            My configuration for EventBus to use Kafka is in AppModule for each service. For instance, Customer.

            And the EventBus observable subject$ is configured for the events in KafkaService.

            Here are the application logs (added // for my comments).

            customer-svc (Command side)

            ...

            ANSWER

            Answered 2020-Oct-15 at 08:38

            The CQRS module registers the EventHandlers automatically by looking at the providers list. By using EventBus.register() we can add additional subscriptions.

            This commit resolves the issue.

            By removing the EventHandlers list from EventBus.register(), I was able to subscribe to them only once and hence resolve the duplicate message issue.

            Source https://stackoverflow.com/questions/63864255

            QUESTION

            CQRS with REST APIs
            Asked 2020-Oct-09 at 12:45

            I am building a REST service over CQRS using EventSourcing to distribute changes to my domain across services. I have the REST service up and running, with a POST endpoint for creating the initial model and then a series of PATCH endpoints to change the model. Each end-point has a command associated with it that the client sends as a Content-Type parameter. For example, Content-Type=application/json;domain-command=create-project. I have the following end-points for creating a Project record on my task/project management service.

            • api.foo.com/project
              • Verb: POST
              • Command: create-project
              • What it does: Inserts a new model in the event store with some default values set
            • api.foo.com/project/{projectId}
              • Verb: PATCH
              • Command: rename-project
              • What it does: Inserts a project-renamed event into the event store with the new project name.
            • api.foo.com/project/{projectId}
              • Verb: PATCH
              • Command: reschedule-project
              • What it does: Inserts a project-rescheduled event into the event store with the new project due date.
            • api.foo.com/project/{projectId}
              • Verb: PATCH
              • Command: set-project-status
              • What it does: Inserts a project-status-changed event into the event store with the new project status (Active, Planning, Archived etc).
            • api.foo.com/project/{projectId}
              • Verb: DELETE
              • Command: delete-project
              • What it does: Inserts a project-deleted event into the event store

            Traditionally in a REST service you would offer a PUT endpoint so the record could be replaced. I'm not sure how that works in the event-sourcing + CQRS pattern. Would I only ever use POST and PATCH verbs?

            I was concerned I was to granular and that every field didn't need a command associated with it. A PUT endpoint could be used to replace pieces. My concern though was that the event store would get out of sync so I just stuck with PATCH endpoints. Is this level of granularity typical? For a model with 6 properties on it I have 5 commands to adjust the properties of the model.

            ...

            ANSWER

            Answered 2020-Jul-09 at 19:54

            One question that comes to mind is, is REST the right paradigm for CQRS at all?

            One completely different way to structure this is to not have action-focused endpoints, but instead structure your REST API as a series of events that you add new events to (with POST).

            Events should be immutable and append-only, so maybe a DELETE method doesn't make that much sense for mutations.

            If you're going all in with CQRS (good luck, I've heard the war stories) I would be inclined to build an API that reflects that model well.

            Source https://stackoverflow.com/questions/62822639

            QUESTION

            Manage sagas between a microservice that uses axon and one that doesn't?
            Asked 2020-Jun-29 at 09:35

            I'm working on a project where there are, for the sake of this question, two microservices:

            1. An new OrderService (Spring Boot)
            2. A "legacy" Invoice Service (Jersey Web Application)

            Additionally, there is a RabbitMQ message broker.

            In the OrderService, we've used the Axon framework for event-sourcing and CQRS.

            We would now like to use sagas to manage the transactions between the OrderService and InvoiceService.

            From what I've read, in order to make this change, we would need to do the following:

            1. Switch from a SimpleCommandBus -> DistributedCommandBus
            2. Change configuration to enable distributed commands
            3. Connect the Microservices either using SpringCloud or JCloud
            4. Add AxonFramework to the legacy InvoiceService project and handle the saga events received.

            It is the fourth point where we have trouble: the invoice service is maintained by a separate team which is unwilling to make changes.

            In this case, is it feasible to use the message broker instead of the command gateway. For instance, instead of doing something like this:

            ...

            ANSWER

            Answered 2020-Jun-29 at 09:35

            First off, and not completely tailored towards your question, you're referring to the Axon Extensions to enable distributed messaging. Although this is indeed an option, know that this will require you to configure several separate solutions dedicated for distributed commands, events and event storage. Using a unified solution for this like Axon Server will ensure that a user does not have to dive in three (or more) different approaches to make it all work. Instead, Axon Server is attached to the Axon Framework application, and it does all the distribution and event storage for you.

            That thus means that things like the DistributedCommandBus and SpringAMQPPublisher are unnecessary to fulfill your goal, if you would use Axon Server.

            That's a piece of FYI which can simplify your life; by no means a necessity of course. So let's move to your actual question:

            Is this a valid approach?

            I think it is perfectly fine for a Saga to act as a anti corruption layer in this form. A Saga states that it reacts on events and send operations. Whether those operations are in the form of commands or another third party service is entirely up to you.

            Note though that I feel AMQP is more a solution for distributed events (in a broadcast approach) than that it's a means to send commands (to a direct handler). It can be morphed to suit your needs, but I'd regard it as suboptimal for command dispatching as it needs to be adjusted.

            Lastly, make sure that your Saga can cope with exception from sending those operations over RabbitMQ. You wouldn't want the Invoice service to fail on that message and having your Order service's Saga think it's on a happy path with your transaction of course.

            Concluding though, it's indeed feasible to use another message broker within a Saga.

            Is there a documented way of handling this kind of scenario in Axon?

            There's no documented Axon way to deal with such a scenario at the moment, as there is no "one size fits all" solution. From a pure Axon approach, using commands would be the way to go. But as you stated, that's not an option within your domain due to an (unwilling?) other team. Hence you would track back to the actual intent of a Saga, without taking Axon into account, which I would summarize in the following:

            • A Saga manages a complex business transaction.
            • Reacts on things happening (events) and sends out operations (commands).
            • The Saga has a notion of time.
            • The Saga maintains state over time to know how to react.

            That's my two cents, hope this helps you out!

            Source https://stackoverflow.com/questions/62557313

            QUESTION

            Can I persist events for other actors?
            Asked 2020-May-16 at 18:48

            Using akka-typed I'm trying to create an event-sourced application in which a command on an actor can cause effect on another actor. Specifically I have the following situation:

            • RootActor
            • BranchActor (it's the representation of a child of the Root)

            When RootActor is issued a CreateBranch command, validation happens, and if everything is o.k. the results must be:

            1. RootActor will update the list of children of that actor
            2. BranchActor will be initialized with some contents (previously given in the command)
            3. RootActor replies to the issuer of the command with OperationDone

            Right now the only thing I could come up with is: RootActor processes the Event and as a side effect issues a command to the BranchActor, which in turn saves an initialization eventt, replies to the RootActor, which finally replies to the original issuer.

            This looks way too complicated, though, because:

            1. I need to use a pipe to self mechanism, which implies that
              • I need to manage internal commands as well that allow me to reply to the original issuer
              • I need to manage the case where that operation might fail, and if this fails, it means that the creation of a branch is not atomic, whereas saving two events is atomic, in the sense that either both are saved or neither is.
            2. I need to issue another command to another actor, but I shouldn't need to do that, because the primary command should take care of everything
            3. The new command should be validated, though it is not necessary because it comes from the system and not an "external" user in this case.

            My question then is: can't I just save from the RootActor two events, one for self, and one for a target BranchActor? Also, as a bonus question: is this even a good practice for event-sourcing?

            ...

            ANSWER

            Answered 2020-May-16 at 18:48

            My question then is: can't I just save from the RootActor two events, one for self, and one for a target BranchActor?

            No. Not to sound trite, but the only thing you can do to an actor is to send a message to it. If you must do what you are doing you are doing, you are on the right path. (e.g. pipeTo etc.)

            is this even a good practice for event-sourcing?

            It's not a good practice. Whether it's suboptimal or a flat out anti-pattern is still debatable. (I feel like I say say this confidently because of this Lightbend Discussion thread where it was debated with one side arguing "tricky but I have no regrets" and the other side arguing "explicit anti-pattern".)

            To quote someone from an internal Slack (I don't want attribute him without his permission, but I saved it because it seemed to so elegantly sum up this kind of scenario.)

            If an event sourced actor needs to contact another actor to make the decision if it can persist an event, then we are not modeling a consistency boundary anymore. It should only rely on the state that [it has] in scope (own state and incoming command). … all the gymnastics (persist the fact that its awaiting confirmation, stash, pipe to self) to make it work properly is an indication that we are not respecting the consistency boundary.

            If you can't fix your aggregates such that one actor is responsible for the entire consistency boundary the better practice is to enrich the command beforehand: essentially building a Saga pattern.

            Source https://stackoverflow.com/questions/61840307

            QUESTION

            Event Sourcing: proper way of rolling back aggregate state
            Asked 2020-May-09 at 03:57

            I'm looking for an advice related to the proper way of implementing a rollback feature in a CQRS/event-sourcing application.

            This application allows to a group of editors to edit and update some editorial content, an editorial news for instance. We implemented the user interface so that each field has an auto save feature and now we would like to provide our users the possibility to undo the operations they did, so that it is possible to rollback the editorial news to a previous known state.
            Basically we would like to implement something like to the undo command that you have in Microsoft Word and similar text editors. In the backend, the editorial news is an instance of an aggregate defined in our domain and called Story.

            We have discussed some ideas to implement the rollback and we are looking for an advice based on real world experiences in similar projects. Here is our considerations about this feature.

            How rollback works in real world business domains

            First of all, we all know that in real world business domains what we are calling rollback is obtained via some form of compensation event.

            Imagine a domain related to some sort of service for which it is possible to buy a subscription: we could have an aggregate representing a user subscription and an event describing that a charge has been associated to an instance of the aggregate (the particular subscription of one of the customers). A possible implementation of the event is as follows:

            ...

            ANSWER

            Answered 2018-Feb-01 at 14:05

            How the compensation events are generated should be the concern of the Story aggregate (after all, that's the point of an aggregate in event sourcing - it's just the validator of commands and generator of events for a particular stream).

            Presumably you are following something like a typical CQRS/ES flow:

            • client sends an Undo command, which presumably says what version it wants to undo back to, and what story it is targetting
            • The Undo Command Handler loads the Story aggregate in the usual way, either possibly from a snapshot and/or by applying the aggregate's events to the aggregate.
            • In some way, the command is passed to the aggregate (possibly a method call with args extracted from the command, or just passing the command directly to the aggregate)
            • The aggregate "returns" in some way the events to persist, assuming the undo command is valid. These are the compensating events.
            • compute the compensation event for each of the occurred events

            ...

            Unfortunately, the second step of the previous procedure is not always possible

            Why not? The aggregate has been passed all previous events, so what does it need that it doesn't have? The aggregate doesn't just see the events you want to roll back, it necessarily processes all events for that aggregate ever.

            You have two options really - reduce the book-keeping that the aggregate needs to do by having the command handler help out in some way, or the whole process is managed internally by the aggregate.

            Command handler helps out: The command handler extracts from the command the version the user wants to roll back to, and then recreates the aggregate as-of that version (applying events in the usual way), in addition to creating the current aggregate. Then the old aggregate gets passed to the aggregate's undo method along with the command, so that the aggregate can then do state comparison more easily.

            You might consider this to be a bit hacky, but it seems moderately harmless, and could significantly simplify the aggregate code.

            Aggregate is on its own: As events are applied to the aggregate, it adds to its state whatever book-keeping it needs to be able to compute the compensating events if it receives an undo command. This could be a map of compensating events, pre-computed, a list of every previous state that can potentially be reverted to (to allow state comparison), the list of events the aggregate has processed (so it can compute the previous state itself in the undo method), or whatever it needs, and it just stores it in its in-memory state (and snapshot state, if applicable).

            The main concern with the aggregate doing it on its own is performance - if the size of the book-keeping state is large, the simplification of allowing the command handler to pass the previous state would be worthwhile. In any case, you should be able to switch between the approaches at any time in the future without any issues (except possibly needing to rebuild your snapshots, if you have them).

            Source https://stackoverflow.com/questions/48531869

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install event-sourcing

            Install composer in your project:.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/goodby/event-sourcing.git

          • CLI

            gh repo clone goodby/event-sourcing

          • sshUrl

            git@github.com:goodby/event-sourcing.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link