1. 상품 등록 (seq_product_create)
sequenceDiagram
autonumber
participant Admin as Client (ADMIN)
participant Product as product-service
participant DB as PostgreSQL
Note over Admin,DB: 상품 등록
Admin->>Product: POST /api/v1/admin/products
Product->>DB: INSERT p_products
DB-->>Product: OK
Product->>DB: INSERT p_inventories
DB-->>Product: OK
Note over Product,DB: 하나의 트랜잭션으로 저장
Product-->>Admin: 201 Created\n(productId, availableQuantity)
Note over Product,DB: 상품 등록과 재고 초기화는<br/>하나의 트랜잭션으로<br/>재고 생성 실패 시 상품도 롤백
2. 상품 수정 (seq_product_update)
- 드롭 활성 여부 확인 후 상품 수정 및 캐시 무효화 흐름
sequenceDiagram
autonumber
participant Admin as Client (ADMIN)
participant Product as product-service
participant Drop as drop-service
participant DB as PostgreSQL
participant Redis
Note over Admin,Redis: 상품 수정
Admin->>Product: PATCH /api/v1/admin/products/{productId}
Product->>Drop: GET /internal/v1/drops/products/{productId}/active
Drop-->>Product: {hasActiveDrop: true/false}
alt hasActiveDrop == true
Product-->>Admin: 409 ACTIVE_DROP_EXISTS
else hasActiveDrop == false
Product->>DB: UPDATE p_products
DB-->>Product: 수정 완료
Note over Product,Redis: @TransactionalEventListener(AFTER_COMMIT)
Product->>Redis: @CacheEvict (상품 캐시 무효화)
Product-->>Admin: 200 OK
end
3. 상품 삭제 (seq_product_delete)
- 드롭 활성 여부 확인 후 상품 소프트 삭제 흐름
sequenceDiagram
autonumber
participant Admin as Client (ADMIN)
participant Product as product-service
participant Drop as drop-service
participant DB as PostgreSQL
Note over Admin,DB: 상품 삭제
Admin->>Product: DELETE /api/v1/admin/products/{productId}
Product->>Drop: GET /internal/v1/drops/products/{productId}/active
Drop-->>Product: {hasActiveDrop: true/false}
alt hasActiveDrop == true
Product-->>Admin: 409 ACTIVE_DROP_EXISTS
else hasActiveDrop == false
Product->>DB: UPDATE p_products SET deleted_at = now()
DB-->>Product: 소프트 삭제 완료
Product-->>Admin: 200 OK (productId, deletedAt)
end
Note over Product,DB: deleted_at 기록 소프트 삭제 (주문 내역 상품명 유지를 위해 하드 삭제 미사용)
4. 재고 수동 수정 (seq_inventory_update)
- 드롭 활성 여부 확인 후 재고 수량 수동 수정 흐름
sequenceDiagram
autonumber
participant Admin as Client (ADMIN)
participant Product as product-service
participant Drop as drop-service
participant DB as PostgreSQL
participant Redis
Note over Admin,Redis: 재고 수동 수정
Admin->>Product: PATCH /api/v1/admin/products/{productId}/inventories
Product->>Drop: GET /internal/v1/drops/products/{productId}/active
Drop-->>Product: {hasActiveDrop: true/false}
alt hasActiveDrop == true
Product-->>Admin: 409 ACTIVE_DROP_EXISTS
else hasActiveDrop == false
Product->>DB: UPDATE p_inventories SET total_quantity = ?
DB-->>Product: 수정 완료
Note over Product,Redis: @TransactionalEventListener(AFTER_COMMIT)
Product->>Redis: @CacheEvict (상품 캐시 무효화)
Product-->>Admin: 200 OK (inventoryId, totalQuantity, availableQuantity)
end
Note over Product: reason 필드는<br>감사 로그(log.info)로 기록
5. 재고 확정 차감 (seq_stock_confirm)
payment.completed 수신 후 재고 차감 및 SAGA 보상 흐름
sequenceDiagram
autonumber
participant K as Kafka
participant C as PaymentCompletedConsumer<br/>(concurrency=3)
participant S as Semaphore(3)
participant I as InventoryService
participant DB as PostgreSQL
Note over C,DB: 재고 확정 차감 (SAGA + 동시성 방어)
K->>C: payment.completed 수신<br/>(파티션당 최대 3개 동시 처리)
C->>S: tryAcquire(2s)
alt 2초 내 획득 실패 (동시 요청 과다)
S-->>C: 획득 실패
C-->>K: DeductionBusyException 발생 (예외 전파)
Note left of K: DefaultErrorHandler 재시도 처리<br/>(최대 3회 초과 시 DLT로 격리, SAGA 보상 아님)
else 세마포어 획득 성공
S-->>C: permit 획득
C->>I: confirmDeduct(event)
I->>DB: SELECT p_processed_events<br/>(중복 이벤트 확인)
DB-->>I: 처리 결과
alt 이미 처리된 eventId
I-->>C: 처리 스킵 (중복 방지)
else 미처리 eventId
I->>DB: SELECT p_inventories (@Version 낙관적 락)
alt 재고 차감 성공
I->>DB: UPDATE p_inventories<br/>SET sold_quantity = sold_quantity + 1
I->>DB: INSERT p_outbox_events<br/>(STOCK_DEDUCTED)
I->>DB: INSERT p_processed_events<br/>(eventId 저장)
Note over I,DB: Outbox Poller (0.5초 주기)
I-->>K: stock.deducted 발행
else OptimisticLockException
I->>DB: INSERT p_failed_event_logs<br/>(UNRESOLVED)
I->>DB: INSERT p_outbox_events<br/>(STOCK_FAILED)
Note over I,DB: Outbox Poller (0.5초 주기)
I-->>K: stock.failed 발행
Note left of K: Payment Service → 결제 취소 보상 트랜잭션
else InsufficientStockException (재고 부족)
I->>DB: INSERT p_failed_event_logs<br/>(UNRESOLVED)
I->>DB: INSERT p_outbox_events<br/>(STOCK_FAILED)
Note over I,DB: Outbox Poller (0.5초 주기)
I-->>K: stock.failed 발행
Note left of K: Payment Service → 결제 취소 보상 트랜잭션
end
end
I->>S: release()
end