Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UPDATEがシステムを複雑にする? イミュータブルデータモデルのすすめ

UPDATEがシステムを複雑にする? イミュータブルデータモデルのすすめ

PHPカンファレンス新潟2025登壇資料

Avatar for a.shimomura

a.shimomura

June 01, 2025
Tweet

More Decks by a.shimomura

Other Decks in Programming

Transcript

  1. • 事業活動のヒト • 業務の関心のモノ • ユーザー、担当者、商品、店舗... データの種類 リソース • 過去に起きたコト

    • 注文、予約、キャンセル... イベント UPDATEして OK! UPDATEは NG! “過去に起きたこと ”が 更新されるわけないしな …
  2. “起きたコト ”が変更されることはない 起きたコト 金額 ユーザーID 日時 入金 3,000円 1 2024/11/21

    10:00 入金 4,000円 1 2024/11/21 10:30 出金 6,000円 1 2024/11/21 11:00 入金 2,000円 1 2024/11/21 11:30
  3. “起きたコト ”から今の状態を計算できる 起きたコト 金額 ユーザー ID 日時 入金 3,000円 1

    2024/11/21 10:00 入金 4,000円 1 2024/11/21 10:30 出金 6,000円 1 2024/11/21 11:00 入金 2,000円 1 2024/11/21 11:30 残高 3,000円
  4. The biggest outcome of the summit was recognizing that when

    people talk about “events”, they actually mean some quite different things. Martin Fowler 「What do you mean by “Event-Driven”?」 https://martinfowler.com/articles/201701-event-driven.html イベント is 何
  5. LaravelにはEvent機能がある class SendPodcastNotification { public function handle(PodcastProcessed $event): void {

    // ... } } https://laravel.com/docs/12.x/events 引数で発行された イベントを受け取る
  6. LaravelにはEvent機能がある class SendPodcastNotification { public function handle(PodcastProcessed $event): void {

    // ... } } https://laravel.com/docs/12.x/events キューとかで動くが 同期的にも動く
  7. $dispatchesEvents class User extends Authenticatable { protected $dispatchesEvents = [

    'saved' => UserSaved::class, 'deleted' => UserDeleted::class, ]; } https://laravel.com/docs/12.x/eloquent
  8. $dispatchesEvents class User extends Authenticatable { protected $dispatchesEvents = [

    'saved' => UserSaved::class, 'deleted' => UserDeleted::class, ]; } https://laravel.com/docs/12.x/eloquent Saveされたら UserSavedイベントを 発行
  9. The Japanese have a small word - ma - for

    "that which is in between" - perhaps the nearest English equivalent is "interstitial". The key in making great and growable systems is much more to design how its modules communicate rather than what their internal properties and behaviors should be. 日本語には「間」という言葉がある。おそらく最も近い英語は「interstitial」だろう。 偉大で成長可能なシステムを作る上で重要なのは、モジュールの内部特性や動 作よりも、モジュールがどのようにコミュニケーションをとるかを設計することだ。 (意訳) Alan C.Kay http://wiki.c2.com/?AlanKayOnMessaging