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

Multiple databases repository #740

Merged
merged 35 commits into from
Sep 15, 2020
Merged

Conversation

mpraglowski
Copy link
Member

@mpraglowski mpraglowski force-pushed the multiple-databases-repository branch from 04484e0 to 97be130 Compare July 30, 2020 10:10
@mpraglowski mpraglowski force-pushed the multiple-databases-repository branch from 204001f to 53c4884 Compare August 18, 2020 16:17
@mpraglowski
Copy link
Member Author

Rebased with #753 - only sample app here

@mpraglowski mpraglowski force-pushed the multiple-databases-repository branch from 53c4884 to 2af5406 Compare September 11, 2020 17:39
App generated with RES template with options:

```
rails new sample --template "https://railseventstore.org/new" --skip-spring --skip-listen --skip-bootsnap --skip-git --skip-keeps --skip-action-text --skip-active-storage --skip-action-cable --skip-action-mailer --skip-action-mailbox --skip-sprockets --skip-javascript --skip-turbolinks --skip-webpack-install --skip-yarn --skip-test --skip-system-test
```
The connected_active_record gem is not needed. Alctually, I think it is
even not the best way to do it. Just
RailsEventStoreActiveRecord::EventRepository with given base abstract
class is enough. And it is better.

The idea is:
* each BC module need to implement it's own AR base class,
* any models used by this BC should inherit from this base class,
* BCs data will be now fully separated from main app data (separate dbs)
* the only way to interact between BCs are:
  * direct API calls (including sending commands to command bus)
  * publishing and handling domain events using BC's public event store

Regarding the event stores:
* each BC has it's own event store where BC's private domain events are
  stored,
* this private domain events must not leak outside the BC boundary,
* any domain event published by BC to external world is stored in public
  event store (defined on application level)
* publishing to public event store could use some patterns like Fat
  Events, Outbox. See more https://verraes.net/2019/05/ddd-msg-arch/
From https://github.com/RailsEventStore/cqrs-es-sample-with-res
with some changes:
* RSpec instead of MiniTest
* use RES RSpec matchers
Because of Rails initialization process.
No database configurations ready when we need to initialize
new number generator instance. This way (by using factory)
we delay it's initialization to the moment when it is really needed.
And at this time database is ready waiting for connections :)
Because one could not link to events from different event store.
A separate model for process state is needed here.
This could be implemented as a snapshoot event and reading only
last event from process stream but I've gone with AR based
process state model to show that typical AR models could
be also used in multiple databases model.
Needed to run test in scope of the single BC
@mpraglowski mpraglowski force-pushed the multiple-databases-repository branch from 2af5406 to c8683d1 Compare September 15, 2020 08:32
@mpraglowski mpraglowski merged commit f443eeb into master Sep 15, 2020
@mpraglowski mpraglowski deleted the multiple-databases-repository branch September 15, 2020 08:35
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.

1 participant