モデリングについて勉強メモ

モデリングについて自分の中で言語化できるように勉強したのでメモします。

モデリングとは

  • 現実世界の複雑な事象をシステムとして扱える形に抽象化する作業

なので

  • 正解は一つではない
  • 抽象レベルは複数存在する
  • 業務理解と技術理解の両面が必要
  • モデルの質でプロダクト開発全体が影響される

モデリングスキルの鍛え方

  • コードを書く前にモデルを書いてみる.
    • UML、ER図、状態遷移図など
  • 新規プロダクトを作る時は業務プロセスをモデル化する.
  • 実際の巨大アプリを逆モデリングしてみる.

AmazonにおけるECの注文処理を逆モデリングしてみる

  • 対象範囲.
    • 商品カタログ
    • 在庫管理.
    • カート~注文.
    • 決済.
    • 倉庫→配送.
    • 返品・返金.

商品カタログ

  • 主なオブジェクト.
Product
 ├── productId
 ├── title
 ├── description
 ├── categories[]
 └── attributes (brand, size, color, …)

Offer
 ├── offerId
 ├── productId
 ├── sellerId
 ├── price
 ├── condition
 ├── shippingOptions
 └── availability
  • Productは検索・閲覧用の情報.
  • 「誰がいくらで売っているか」を表すのがOffer

在庫管理.

StockLevel
 ├── offerId
 ├── warehouseId
 ├── availableQty
 ├── reservedQty
 └── inboundQty   (入荷予定)

Reservation
 ├── reservationId
 ├── offerId
 ├── orderId
 ├── quantity
 ├── expiresAt
  • 在庫は倉庫別に管理.
  • 注文時にReservationが作られる(在庫確保).
  • 一定時間でexpiresする→決済失敗やカート放置による在庫拘束を避ける.

カート&注文.

Cart
 ├── cartId
 ├── customerId
 └── CartItems[]

CartItem
 ├── offerId
 ├── quantity
 └── priceSnapshot

注文.

Order
 ├── orderId
 ├── customerId
 ├── status
 ├── orderItems[]
 ├── shippingAddress
 ├── paymentStatus
 └── fulfillmentRequests[]

OrderItem
 ├── offerId
 ├── price
 ├── quantity
 └── shipmentId

決済.

PaymentIntent
 ├── intentId
 ├── orderId
 ├── amount
 ├── method
 └── status

Charge
 ├── chargeId
 ├── intentId
 ├── amount
 └── status

Refund
 ├── refundId
 ├── chargeId
 ├── amount
 └── status

フルフィルメント

FulfillmentRequest
 ├── requestId
 ├── orderId
 ├── warehouseId
 ├── items[]
 └── status

Picking
 ├── itemId
 ├── pickerId
 └── pickedAt

Packing
 ├── packageId
 ├── weight
 ├── dimensions
 └── packedAt

Shipping
 ├── trackingId
 ├── carrier
 ├── shippedAt
 └── deliveredAt

返品

ReturnRequest
 ├── requestId
 ├── orderId
 ├── items[]
 ├── reason
 └── status

RefundInstruction
 ├── instructionId
 ├── requestId
 ├── amount
 └── method

という感じになると思いました。
コード書く前のモデリングの精度上げることができるようにしたいと思います。