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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
n.kakuta
August 27, 2020
Programming
0
960
RailsEventStore使ってみた
サンプルアプリのgithubはこちらです
https://github.com/naoki-k/book-rental
n.kakuta
August 27, 2020
Tweet
Share
Other Decks in Programming
See All in Programming
要求定義・仕様記述・設計・検証の手引き - 理論から学ぶ明確で統一された成果物定義
orgachem
PRO
1
220
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
210
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
470
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.6k
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
180
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
4k
AI巻き込み型コードレビューのススメ
nealle
2
1.2k
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
480
Data-Centric Kaggle
isax1015
2
780
Oxlintはいいぞ
yug1224
5
1.4k
CSC307 Lecture 08
javiergs
PRO
0
670
Featured
See All Featured
Discover your Explorer Soul
emna__ayadi
2
1.1k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
120
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
62
50k
It's Worth the Effort
3n
188
29k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
750
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
140
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
120
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
280
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
110
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