STK10-14 추천 재계산 흐름

작업 내용

worker가 collected.v1 수신 시 추천 예측을 재계산·영속화하는 수직 슬라이스다. worker는 오케스트레이션만, 계산은 ml, 영속화는 BE (ADR-010).

  • worker application: RefreshRecommendationUseCase — BE에서 후보군·수급 팩터 read → ml 추천 compute(팩터 입력, STK10-10) → BE 추천 예측 upsert
  • worker infrastructure: BE read/persist client, ml compute client
  • backend presentation: 추천 예측 upsert API (POST 멱등, (scope_key, base_date) 기준)
  • backend 영속화: 추천 예측 스냅샷 테이블 — 기존 snapshot 저장소 재사용 가능 여부를 main(STK8/STK9)에서 확인, 없으면 신설

다이어그램

처리 흐름

sequenceDiagram
    participant EW as EventWorker
    participant UC as RefreshRecommendationUseCase
    participant BE as backend API
    participant ML as ml compute
    EW->>UC: refresh(baseDate)
    UC->>BE: 후보군·수급 팩터 read
    UC->>ML: 추천 compute(inputs + factors)
    ML-->>UC: recommendations
    UC->>BE: upsert 추천 예측 (멱등)

클래스 의존

flowchart LR
    UC[RefreshRecommendationUseCase] --> BEClient[backend client]
    UC --> MLClient[ml client]
    BEClient --> BE[backend 추천 upsert API]
    MLClient --> ML[ml 추천 compute]

테스트 케이스

  • collected.v1 처리 시 추천이 재계산되어 BE에 영속화된다
  • 동일 baseDate 재처리 시 멱등하게 덮어쓰기된다
  • 수급 팩터가 ml 입력으로 전달돼 가중 반영된다
  • ml·BE 호출 실패 시 예외가 전파돼 재시도/DLQ 대상이 된다 (부분 저장 없음)
  • BE 추천 upsert API가 멱등 동작한다