Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RailsEventStore使ってみた
Search
n.kakuta
August 27, 2020
Programming
0
930
RailsEventStore使ってみた
サンプルアプリのgithubはこちらです
https://github.com/naoki-k/book-rental
n.kakuta
August 27, 2020
Tweet
Share
Other Decks in Programming
See All in Programming
オープンセミナー2025@広島「君はどこで動かすか?」アンケート結果
satoshi256kbyte
0
230
FindyにおけるTakumi活用と脆弱性管理のこれから
rvirus0817
0
350
Langfuseと歩む生成AI活用推進
licux
3
320
Claude Codeで実装以外の開発フロー、どこまで自動化できるか?失敗と成功
ndadayo
3
1.8k
ProxyによるWindow間RPC機構の構築
syumai
1
260
Vue・React マルチプロダクト開発を支える Vite
andpad
0
110
時間軸から考えるTerraformを使う理由と留意点
fufuhu
8
3.2k
機能追加とリーダー業務の類似性
rinchoku
0
180
MLH State of the League: 2026 Season
theycallmeswift
0
210
兎に角、コードレビュー
mitohato14
0
160
個人軟體時代
ethanhuang13
0
280
もうちょっといいRubyプロファイラを作りたい (2025)
osyoyu
0
230
Featured
See All Featured
Making Projects Easy
brettharned
117
6.4k
The Pragmatic Product Professional
lauravandoore
36
6.8k
Imperfection Machines: The Place of Print at Facebook
scottboms
268
13k
How to train your dragon (web standard)
notwaldorf
96
6.2k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Automating Front-end Workflow
addyosmani
1370
200k
4 Signs Your Business is Dying
shpigford
184
22k
Code Review Best Practice
trishagee
70
19k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
284
13k
Producing Creativity
orderedlist
PRO
347
40k
Testing 201, or: Great Expectations
jmmastey
45
7.6k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
Transcript
RailsEventStore使ってみた Da Vinch Studio アプリ部所属 角田 直己 2020/08/27
だれ? エンジニア2年目 一年間のRails研修を受けた後,アプリ部に所属 現在はAndroid・iOSのアプリ開発を担当
アプリはオブジェクトの生存時間が長い 関心の分離のため,対話的なプログラミングが求められる (Observer, Rx, イベントドリブン etc...) Webとアプリの違い
RailsでCQRS×ESを試してみる Railsのアーキテクチャも試したい
事前知識 ・CQRS(コマンドクエリ責務分離) ・Event Sourcing
CQRS(コマンドクエリ責務分離) 書き換え操作(コマンド)と読み込み操作(クエリ)の分離 CRUD 出典: http://sensetecnic.com/cqrs-and-event-sourcing-for-the-iot/
Event Sourcing と State Sourcing State Sourcing (一般的なアプリケーション) → 状態を管理する
Event Sourcing → 過程を管理する example: git 通帳番号 残金 1110001 10,000 通帳番号 日付 取引内容 支払い金額 預かり金額 1110001 1/1 預金 20,000 1110001 1/4 クレジットカード 5,000 1110001 1/5 クレジットカード 5,000 → 残高10,000(状態)
Event Sourcing × CQRS 出典: http://sensetecnic.com/cqrs-and-event-sourcing-for-the-iot/
自由に触ってみてください! 今回はアーキテクチャの話なので,この裏側をお話しします サンプルアプリ作ってみた
None
None
None
主役 gem “rails_event_store” (https://railseventstore.org/) EventStoreとEventのPub/Sub機能の提供
アプリの要件 今回のコマンド ・本を登録する ・本を貸し出す ・本を返却する ・本を破棄する これらの操作履歴を閲覧できること!
今回の設計 出典: https://assist-software.net/blog/introduction-event-sourcing-ruby-rails
サンプルコードを見ていく
コントローラ 各アクションは,コマンドの生成と実行をする コマンドはコントローラに実行の成否を返す
コマンド
ドメインモデル
サブスクライバー リードモデルへの同期を担当する 今回はリレーショナル DBの更新のみ
機能したか ・メディア系アプリケーション等,リソースのライフサイクルを軸に考える場合は返って複雑さを 高める ・EventSoucingが必要な場合は,CQRSは簡単に機能する
導入すべきシーン ・イベントの過程が価値をもつ場合 (ポイントサービス等は,ユーザーが過程に関心を持つ) ・複数ユーザーが同一リソースで共同作業をする場合 (操作履歴がundoを可能にする) ・アプリケーションに部分的に導入することが現実的
感想 新しいアーキテクチャを試して,選択肢が広がった アプリ部でもAPIサーバーの開発に活かせそう
参考文献 ・From CRUD to CQRS https://medium.com/@antonnalivayko1/from-crud-to-cqrs-part1-cqrs-cbeac0350043 ・CQRS and Event Sourcing
for the IoT http://sensetecnic.com/cqrs-and-event-sourcing-for-the-iot/ ・RailsEventStore Docs https://railseventstore.org/ ・Introduction to event sourcing in Ruby on Rails https://assist-software.net/blog/introduction-event-sourcing-ruby-rails