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
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
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
110
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
4k
24時間止められないシステムを守る-医療ITにおけるランサムウェア対策の実際
koukimiura
1
120
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
390
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
140
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
150
CSC307 Lecture 06
javiergs
PRO
0
690
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
1k
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
310
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
7.5k
SourceGeneratorのススメ
htkym
0
200
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
40
2.3k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
260
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
The Invisible Side of Design
smashingmag
302
51k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
190
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
58
50k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
220
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
A Soul's Torment
seathinner
5
2.3k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Crafting Experiences
bethany
1
50
What does AI have to do with Human Rights?
axbom
PRO
0
2k
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