Eventide on Rails
The Eventide Project team has started work on Eventide on Rails: an integration of Eventide and Rails that brings pub/sub, event sourcing, evented systems, and messaging to Ruby on Rails apps. Built on Message DB and the Ruby Award winning Eventide Project, Eventide on Rails blends the best of web app development and evented systems and autonomous services into a single stack.
The integration will allow Rails developers to do a number of things that are typically unavailable to stock Rails apps:
- Record business events from within Rails controllers, models, background jobs, mailers, and service objects
- Record an audit trail of changes to ActiveRecord models as an event stream
- Apply data changes made in external services to Rails application data
- Bring event sourcing to Rails apps
- Project a stream of events onto an ActiveRecord model
- Send messages to external pub/sub services via Message DB
- Receive messages from external services via Message DB
The goal of the implementation is not to attempt to turn Rails apps into microservices, since that would largely be a violation of microservices architecture tenets. The goal is to create a harmonious transition between autonomous evented services and web applications, and to encourage and enforce their strict separation while enabling their seamless integration.
The early pre-v1 releases of Eventide on Rails will allow developers to read and write to and from Message DB, to project event-sourced entities from event streams, and to interact with external services via commands and events using the ActiveRecord Postgres connection.
The implementation will allow the co-hosting of the Message DB message store database with a Postgres application database in Rails.
CRUD operations in ActiveRecord will be executed in the same database transaction as the recording of events via Eventide’s writer, making the recording of events atomic with Rails application database operations. This is ultimately the killer feature of Eventide on Rails, but definitely not the only feature. Of course, all other foundational Eventide features will also work within Rails as well, including readers, writers, projections, and even entity stores and handlers.
user_created_event = UserCreated.build(params)
ActiveRecord::Base.transaction do
user = User.create(params)
stream_name = "user-#{user.id}"
eventide_writer.write(user_created_event, stream_name)
end
The enlisting of Eventide’s message writer into ActiveRecord transactions means that Eventide will provide a complete Outbox Pattern implementation for Rails applications. This means that enqueueing Eventide messages will happen in the same atomic transaction as any application data changes saved via ActiveRecord. If an ActiveRecord operation fails or the enqueueing of the message fails, both the ActiveRecord operation and the enqueueing will be rolled back.
Since Eventide also provides a toolkit for developing and hosting external services that process messages, not only does Eventide on Rails enable enqueueing messages in ActiveRecord transactions, it also already provides the means to process those messages in the background, thus completing the full circle of the Outbox Pattern. It’s a complete solution for Rails developers.
These early releases will be fully operational, but they will not provide any rails-specific tooling that makes the whole developer experience familiar and convenient. It will be more friendly to users who have some familiarity with Eventide and who are comfortable with Postgres administration, as co-hosting the message store database within an existing Rails database will be done via Message DB’s installation and administration scripts.
As the implementation matures toward a v1 release, it will gain more features that will enable a more comfortable and automatic Rails developer experience.
As of v1, Message DB will be installable via ActiveRecord migrations, and Rails generators will be included for generating the migrations. Also, rather than configuring the database connection for Eventide objects using Eventide’s own connection settings file, Eventide objects will use the database connection configured by Rails’ database configuration file.
And of course, in keeping with the Eventide Project’s standards, Eventide on Rails will ship with thorough documentation and demos.
So far, the team has done early proofs of concept for both the connection sharing implementation and the ActiveRecord migrations. Following on those succesful results, we proceed to implementing the production code.
We’re not offering hard release date estimates yet, after all, it’s an open source project executed by volunteers in available time. That said, our optimistic estimate is for a v1 release in 3 months. The pessimistic estimate is 6 months. We hope to have an operational pre-release within 1 to 2 months.
Follow the project on GitHub for updates:
https://github.com/eventide-project/eventide-rails
Feel free to follow up with any questions on the Eventide Slack. Join up and join the conversation!
https://eventide-project-slack.herokuapp.com/