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

Buzzvil Billing Data Pipeline

Buzzvil
February 04, 2022

Buzzvil Billing Data Pipeline

By Will

Buzzvil

February 04, 2022
Tweet

More Decks by Buzzvil

Other Decks in Programming

Transcript

  1. Copyright ⓒ All Right Reserved by Buzzvil
    Buzzvil Billing Data Pipeline
    (정산 데이터 이렇게 만들어진다)
    Dev Seminar

    View Slide

  2. Copyright ⓒ All Right Reserved by Buzzvil
    버즈빌 정산 전도(全圖)

    View Slide

  3. Copyright ⓒ All Right Reserved by Buzzvil
    정산?
    (정확히는 매체사 정산)

    View Slide

  4. Copyright ⓒ All Right Reserved by Buzzvil
    정산?
    - 광고주로 부터 광고비를 받고 광고를 받아온다. => 매출 발생(실제로는 매출 가능성 발생)
    - 받아온 광고들을 제휴 매체사 모바일앱을 통해 내보낸다. => 실제 매출 발생
    - 이때 매체사들에게 소정의 수수료를 지급한다. => 정산금액 발생(버즈빌 입장에서는 비용)
    “매체사의 광고 지면에서 발생한 광고 수익을 매체사와 나누어 가져야하는데(RS: Revenue Share),
    이때 매체사에게 지급해야할 금액(Payout)을 계산하는 것을 정산이라 한다"

    View Slide

  5. Copyright ⓒ All Right Reserved by Buzzvil
    지급해야할 금액은 어떻게 만들어질까?
    - 광고의 종류가 다양하다.
    - by Revenue Type
    cpc, cpm, cpi, cpe, cpa, cpl, cps, cpy, cpq, cpinsta, cpk, cpyoutube, cpylike
    - by Lineitem Type
    direct, adnetwork_sdk, adnetwork_rtb, adnetwork_list
    - by Owner
    Buzzvil, Publihser, External
    - 광고가 나가는 매체사 앱과 광고의 지면도 다양하다.
    - 허니스크린, 신한페이판, 리브메이트, 티멤버쉽, 짤, 아만다 등등..
    “광고 타입 별로 정산 하기위해 집계되어야 하는 지면별 수익/비용 데이터(Unit Finance)가
    있다.”
    - 매체사 마다 정산 방식 계약사항이 다르다.
    - 광고의 종류 마다 수익에 대한 공유 비율이 다르다
    - 광고에서 발생한 유저 포인트 적립 금액에 대한 처리도 다 다르다.
    - 등등..
    “각 매체사별로 정산에 필요한 정산식(Payout Strategy)이 있다.”

    View Slide

  6. Copyright ⓒ All Right Reserved by Buzzvil
    최종 정산 금액은 어디서 만들어지는가? - Billingsvc
    Billingsvc 역할
    광고지면에서 발생한 광고 수익 / 비용 집계 데이터를 정산식에 대입하여 최종 정산 금액을
    계산하는 것
    용어 정리
    광고지면 : Unit
    광고수익 : Revenue
    광고비용 : Cost
    지면별 광고 수익/비용 : UnitFinance
    정산식 : Payout Strategy
    최종 정산 금액 : Payout

    View Slide

  7. Copyright ⓒ All Right Reserved by Buzzvil
    Payout은 어떻게 생겼을까?

    View Slide

  8. Copyright ⓒ All Right Reserved by Buzzvil
    Payout? - Billingsvc
    id : pk
    uuid : payout unique key
    local_date: 매달 1일
    unit_contract_uuid: payout 계산에 사용된 계약정보(정산식, Revenue Share, Currency 등)의 key
    unit_id: unit_id
    payout_buzzvil: 버즈빌이 매체사에게 줄돈(정산 금액)
    payout_owner: 매체사가 버즈빌에게 줄돈
    status: payout 상태 (Draft, Approve, Paid)
    unit_finance_id: payout 계산에 사용된 revenue/cost 집계 데이터 key
    access: payout 권한(Private, Public)

    View Slide

  9. Copyright ⓒ All Right Reserved by Buzzvil
    Billingsvc
    Payout

    View Slide

  10. Copyright ⓒ All Right Reserved by Buzzvil
    그럼, Unit별 광고 매출/비용 데이터 집계(UnitFinance)는?
    Payout 계약 사항(UnitContract)은?

    View Slide

  11. Copyright ⓒ All Right Reserved by Buzzvil
    Unit Finance? - Billingsvc
    data_at : 집계 기준 시각(월 단위)
    unit_id
    prefix
    revenue : 매출
    cost : 비용(포인트)
    midfix
    display : 노출형 광고 데이터 집계
    action : 액션형 광고 데이터 집계
    adn_static : and static 광고 데이터 집계
    adn_dynamic : adn dyn 광고 데이터 집계
    imp : imp 형 포인트 타입의 코스트 데이터 집계
    postfix
    direct : 버즈빌 직영업 광고
    owner : 매체사 직영업 광고
    external : 버즈빌 도 매체사 직영업 광고도 아닌 외부 광고
    e.g.
    revenue_display_direct :
    이번달에 특정 유닛에 송출된 display 형 버즈빌 직영업 광고에 대한 매출
    집계
    revenue_action_owner :
    이번달에 특정 유닛에 송출된 action 형 매체사 직영업 광고에 대한 매출
    집계
    cost_action_exteranl :
    이번달에 특정 유닛에 송출된 action 형 외부 광고에 대한 비용 집계
    (포인트 집계)
    Unit Finance : 유닛에서 발생한 revenue / cost 집계 데이터

    View Slide

  12. Copyright ⓒ All Right Reserved by Buzzvil
    Unit Contract? - Billingsvc
    unit_id : 이 계약이 적용되는 unit id
    start_date : 이 계약이 적용되는 시작 시각
    end_date : 이 계약이 적용되는 종료 시각
    contract_id : 이 계약에서 사용되는 rs(revenue share) 정보
    buzzvil_payout_strategy : 이 계약에서 사용되는 buzzvil payout 정산식
    owner_payout_strategy : 이 계약에서 사용되는 owner payout 정산식
    currency : 이 계약에서 사용되는 통화 단위
    point_rate : 이 계약에서 사용되는 포인트 단위
    timezone : 이 계약이 적용되는 유닛의 타임존
    exchange_rate : 이 계약에 적용되는 환율 (원/달러)
    finalized : 이 계약이 정산이 완료되었는지 여부 (finalize 되면 payout 데이터를 수정할 수 없다.)
    Unit Contract : 특정 기간(보통 월 단위) 동안 특정 유닛에 적용될 정산 계약

    View Slide

  13. Copyright ⓒ All Right Reserved by Buzzvil
    Billingsvc
    Payout
    UnitFinance
    UnitContract

    View Slide

  14. Copyright ⓒ All Right Reserved by Buzzvil
    UnitContract 랑 UnitFinance 가 뭔지는 대충 알겠는데,
    Payout과는 정확히 어떻게 엮여 있는 거지?

    View Slide

  15. Copyright ⓒ All Right Reserved by Buzzvil
    Payout Strategy? - Billingsvc
    https://github.com/Buzzvil/billingsvc/blob/3e74fd7b7e21c92b50f912503be72f08079e042c/src/billing/domain/str
    ategy/payout_strategies.py#L21

    View Slide

  16. Copyright ⓒ All Right Reserved by Buzzvil
    Billingsvc
    Payout
    UnitFinance
    UnitContract
    Payout
    Strategy
    Contract

    View Slide

  17. Copyright ⓒ All Right Reserved by Buzzvil
    OK.
    UnitFinance랑 UnitContract 를 PayoutStrategy에서 잘 조합해서
    Payout이 만들어지는 거구나. 👌
    그럼, UnitContract랑 UnitFinance는 어떻게 만들어지는 걸까?

    View Slide

  18. Copyright ⓒ All Right Reserved by Buzzvil
    UnitContract 는 Dash 에서..

    View Slide

  19. Copyright ⓒ All Right Reserved by Buzzvil
    UnitFinance 는 Statssvc 에서..
    Statssvc에도 Billingsvc와 동일한 UnitFinance 데이터가 존재
    Statssvc의 역할 : 버즈빌에서 발생하는 여러가지 데이터들을 집계해 놓는다.

    View Slide

  20. Copyright ⓒ All Right Reserved by Buzzvil
    Statssvc
    UnitFinance
    Billingsvc
    Payout
    UnitFinance
    UnitContract
    Payout
    Strategy
    Contract
    Dash / Finance Manger / Payout Detail View

    View Slide

  21. Copyright ⓒ All Right Reserved by Buzzvil
    UnitContract 는 대시에서 운영자가 세팅하고,
    UnitFinance는 Statssvc에 집계 되어 있는 데이터를 가져다
    쓰는구나..
    그럼, 이런것들을 가지고
    Payout을 계산해주는 것은 언제 어디서 누가 해주는 걸까?

    View Slide

  22. Copyright ⓒ All Right Reserved by Buzzvil
    Airflow
    Airflow :
    DAG 기반으로 데이터 파이프라인을
    쉽고 유연하게 관리할 수 있게 해주는
    파이썬 기반 프레임워크
    (DAG : Directed Acyclic Graph)

    View Slide

  23. Copyright ⓒ All Right Reserved by Buzzvil
    Payout 지도
    Airflow
    Dash / Finance Manger / Payout Detail View
    Statssvc
    UnitFinance
    Billingsvc
    Payout
    UnitFinance
    UnitContract
    Payout
    Strategy
    Contract

    View Slide

  24. Copyright ⓒ All Right Reserved by Buzzvil
    󰢧
    Statssvc의 UnitFinance는 어떻게 집계 되는 것 일까?

    View Slide

  25. Copyright ⓒ All Right Reserved by Buzzvil
    UnitFinance의 Sources - Statssvc
    https://buzzvil.atlassian.net/wiki/spaces/MONEY/pages/1890713692/Billingsvc+Overview#Basic-Data-for-Finance

    View Slide

  26. Copyright ⓒ All Right Reserved by Buzzvil
    (⅕)UnitCreative- Statssvc
    data_at : 집계 시각(시간단위)
    unit_id : 데이터가 발생한 unit
    lineitem_id : 데이터가 발생한 lineitem
    revenue_type : lineitem 의 revenue type
    (cpa, cpinsta, cpk, cpi, cpy, cpc, cpm …)
    lineitem_type : lineitem type
    (A: Direct, E/R/S: ADN)
    unit_orgnization_id : unit 소유 매체사
    lineitem_organization_id : 광고 소유 매체사
    unit_sales : 각 데이터의 revenue 집계
    action_reward : 각 데이터의 action 형 reward 집계
    정산 입장에서 Unit Creative는 시간별/유닛별/라인아이템별로 발생한 revenue 와 action 형 cost의 집계
    데이터

    View Slide

  27. Copyright ⓒ All Right Reserved by Buzzvil
    (⅖)UnitPoint- Statssvc
    data_at : 집계 시각(시간단위)
    unit_id : 데이터가 발생한 unit
    unit_orgnization_id : unit 소유 매체사
    campaign_organization_id : 캠페인 소유 매체사
    point_type : point type (imp, base, wel, bch, ref)
    reward : 각 데이터의 reward 집계
    정산 입장에서 Unit Point는 시간별/유닛별로 발생한 reward(imp, base, wel, bch, ref) 집계 데이터 이다.

    View Slide

  28. Copyright ⓒ All Right Reserved by Buzzvil
    (⅗)UnitAdReward- Statssvc
    정산 입장에서 Unit Ad Reward는 시간별/유닛별로 발생한 reward(cpc, cpm, cpa, cpy) 집계 데이터 이다.

    View Slide

  29. Copyright ⓒ All Right Reserved by Buzzvil
    (⅘)UnitEventReward- Statssvc
    정산 입장에서 Unit Event Reward는 시간별/유닛별로 발생한 event성 reward 집계 데이터 이다.
    event_type : opened, walked, won

    View Slide

  30. Copyright ⓒ All Right Reserved by Buzzvil
    (5/5)AdnetworkReport- Statssvc
    정산 입장에서 AdnetworkReport는 시간별/유닛별로 발생한 adn 광고 revenue 집계 데이터 이다.

    View Slide

  31. Copyright ⓒ All Right Reserved by Buzzvil
    Generate Unit Finance - Statssvc
    generate_unit_finance:
    unit_creative
    unit_point
    unit_ad_reward
    unit_event_reward
    adnetwork_report
    다섯가지 집계 테이블을 적절한
    쿼리로
    Union 하여 하나의 UnitFinance 다시
    집계를 해준다.
    https://github.com/Buzzvil/statssvc/b
    lob/c8dec424f791d79395af5b1c5ffb
    227875fb1e5f/src/stats/adapters/rep
    os/job.py#L404

    View Slide

  32. Copyright ⓒ All Right Reserved by Buzzvil
    Unit Finance 복습
    data_at : 집계 기준 시각(월 단위)
    unit_id
    revenue : 매출
    cost : 비용(포인트)
    display : 노출형 광고 데이터 집계
    action : 액션형 광고 데이터 집계
    adn_static : and static 광고 데이터 집계
    adn_dynamic : adn dyn 광고 데이터 집계
    imp : imp 형 포인트 타입의 코스트 데이터
    집계
    direct : 버즈빌 직영업 광고
    owner : 매체사 직영업 광고
    external : 버즈빌 도 매체사 직영업 광고도
    아닌 외부 광고
    e.g.
    revenue_display_direct :
    이번달에 특정 유닛에 송출된 display 형 버즈빌 직영업 광고에 대한 매출
    집계
    revenue_action_owner :
    이번달에 특정 유닛에 송출된 action 형 매체사 직영업 광고에 대한 매출
    집계
    cost_action_exteranl :
    이번달에 특정 유닛에 송출된 action 형 외부 광고에 대한 비용 집계
    (포인트 집계)
    Unit Finance : 유닛에서 발생한 revenue / cost 집계 데이터

    View Slide

  33. Copyright ⓒ All Right Reserved by Buzzvil
    Payout 지도
    Airflow
    Dash / Finance Manger / Payout Detail View
    Statssvc
    UnitFinance
    Billingsvc
    Payout
    UnitFinance
    UnitContract
    Payout
    Strategy
    Contract
    UnitCreative
    UnitPoint
    UnitAdReward
    UnitEventReward
    AdnetworkReport
    generate
    unit
    finance

    View Slide

  34. Copyright ⓒ All Right Reserved by Buzzvil
    이제 Payout이 뭐고 어떻게 만들어지는 건지는 얼추 감이 온다.
    그런데..
    UnitFinance를 만드는 5가지 집계 데이터들은 또 어디서 오는 것일까
    🤔

    View Slide

  35. Copyright ⓒ All Right Reserved by Buzzvil
    일단 UnitCreative 부터..

    View Slide

  36. Copyright ⓒ All Right Reserved by Buzzvil
    Unit Creative
    Redshift
    vw_statssvc_unit_creative
    ba_statistics_unit_creative
    Airflow
    Statssvc
    UnitCreative
    BA
    statistic_unit_creative
    Jenkins
    Redis
    unit_sales_total
    raw_data_conversion
    reward
    unit_price
    action_reward
    allocation
    &
    participation
    https://buzzvil.atlassian.net/wiki/spaces/BI/pages/1483702567/UnitCreative+metrics#2.-Pipeline-Overview
    Postbacksvc
    postback

    View Slide

  37. Copyright ⓒ All Right Reserved by Buzzvil
    UnitPoint의 뿌리는?

    View Slide

  38. Copyright ⓒ All Right Reserved by Buzzvil
    Unit Point
    Athena(S3)
    g_unit_point
    g_vw_point
    Statssvc
    UnitPoint
    g_stream_point
    g_point
    l_point
    Labmda
    DyanmoStream
    to Firehose
    Firehose
    prod-buzzscreen-point-stream
    DynamoDB
    prod_buzzscreen_point
    DynamoStream
    Airflow
    Postbacksvc
    postback
    BS
    postback
    participation
    https://buzzvil.atlassian.net/wiki/spaces/BI/pages/1158643713/buzzscreen+pointsvc+reward+pipeline

    View Slide

  39. Copyright ⓒ All Right Reserved by Buzzvil
    와.. 복잡하네
    그럼 UnitAdReward 랑 UnitEventReward의 조상은 누구냐?

    View Slide

  40. Copyright ⓒ All Right Reserved by Buzzvil
    Unit Ad Reward & Unit Event Reward
    Athena(S3)
    Airflow
    g_unit_ad_reward
    g_vw_point
    Statssvc
    UnitAdReward
    g_stream_point
    g_point
    l_point
    Labmda
    DyanmoStream
    to Firehose
    Firehose
    prod-pointsvc-point-stream
    participation
    DynamoDB
    prod_pointsvc_point
    DynamoStream
    Postbacksvc
    postback
    Pointsvc
    postback
    https://buzzvil.atlassian.net/wiki/spaces/BI/pages/1158643713/buzzscreen+pointsvc+reward+pipeline
    UnitEventReward
    g_unit_event_reward

    View Slide

  41. Copyright ⓒ All Right Reserved by Buzzvil
    마지막 AdnetworkReport 는..

    View Slide

  42. Copyright ⓒ All Right Reserved by Buzzvil
    Adnetwork Report
    Redshift
    ba_adnetwork_report_data
    adnpreportsvc_report_data
    Statssvc
    AdnetworkReport
    AdnReportsvc
    report_data
    Airflow
    crawl

    View Slide

  43. Copyright ⓒ All Right Reserved by Buzzvil
    버즈빌 정산 전도 완성

    View Slide

  44. Copyright ⓒ All Right Reserved by Buzzvil
    버즈빌 정산 전도(全圖)
    https://buzzvil.atlassian.net/wiki/spaces/MONEY/pages/2661450316

    View Slide

  45. Copyright ⓒ All Right Reserved by Buzzvil
    부록 1 : 경험할 수 있는 것들
    Operations
    - Kubernetes
    - Docker
    Language
    - Python
    - Go
    Database
    - MySQL
    - AWS Redshift
    - AWS Athena
    - AWS DynamoDB
    Message Queue
    - Redis
    Data Pipeline tools
    - Airflow
    - Jenkins
    ETC
    - Protocol Buffer
    - gRPC
    - Vue.js(frontend)
    대용량 데이터 배치 처리 기술 경험
    2022년 1월 현재 unit creative 기준
    - 총 record 수 : 약 8억건
    - 배처 처리 량(1회) : 5만 ~ 10만

    View Slide

  46. Copyright ⓒ All Right Reserved by Buzzvil
    부록 2 : 추가 자료
    - billingsvc overview
    - billingsvc design doc
    - statssvc dsign doc
    - unit creative pipeline
    - reward pipeline
    - billingsvc data catalog

    View Slide

  47. Copyright ⓒ All Right Reserved by Buzzvil
    Thank you
    Will
    2022.2.4

    View Slide