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
920
RailsEventStore使ってみた
サンプルアプリのgithubはこちらです
https://github.com/naoki-k/book-rental
n.kakuta
August 27, 2020
Tweet
Share
Other Decks in Programming
See All in Programming
CIを整備してメンテナンスを生成AIに任せる
hazumirr
0
480
[Codecon - 2025] Como não odiar seus testes
camilacampos
0
100
新しいモバイルアプリ勉強会(仮)について
uetyo
1
240
MySQL9でベクトルカラム登場!PHP×AWSでのAI/類似検索はこう変わる
suguruooki
1
280
11年かかって やっとVibe Codingに 時代が追いつきましたね
yimajo
1
230
Terraform やるなら公式スタイルガイドを読もう 〜重要項目 10選〜
hiyanger
11
2.8k
変化を楽しむエンジニアリング ~ いままでとこれから ~
murajun1978
0
650
フロントエンドのパフォーマンスチューニング
koukimiura
7
2.4k
Strands Agents で実現する名刺解析アーキテクチャ
omiya0555
1
110
大規模FlutterプロジェクトのCI実行時間を約8割削減した話
teamlab
PRO
0
430
オホーツクでコミュニティを立ち上げた理由―地方出身プログラマの挑戦 / TechRAMEN 2025 Conference
lemonade_37
1
420
「次に何を学べばいいか分からない」あなたへ──若手エンジニアのための学習地図
panda_program
3
700
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
462
33k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
110
19k
Balancing Empowerment & Direction
lara
1
520
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
We Have a Design System, Now What?
morganepeng
53
7.7k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Into the Great Unknown - MozCon
thekraken
40
2k
Typedesign – Prime Four
hannesfritz
42
2.7k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
740
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.2k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
332
22k
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