Cookpad の広告配信を支えるアーキテクチャ

Cookpad の広告配信を支えるアーキテクチャ

3b36493b4296ebeb219bcd3ffab3aa2b?s=128

Kenju Wagatsuma

October 03, 2018
Tweet

Transcript

  1. $PPLQBEͷ޿ࠂ഑৴Λ ࢧ͑ΔΞʔΩςΫνϟ $PPLQBE*OD զ࠺ݠथʢ,FOKV8BHBUTVNBʣ 

  2. 8IP Kenju Wagatsuma - Serverside Engineer - Ruby, Go, AWS

    - Recruit HD -> Bit Journey -> Cookpad - github.com/kenju - twitter.com/itiskj - itiskj.hatenablog.com
  3. "SDIJUFDUVSF

  4. 4FSWJDFT • ad4 • admin site • ads • ads

    delivery server • log architecture • Offline … fluentd/S3/Redshift • Realtime … Kinesis Streams/DynamoDB/Lambda
  5. 0WFSBMM"SDIJUFDUVSF BE BET CBUDI ! DBDIF .Z42- .Z42- 4%,

  6. -PH"SDIJUFDUVSF

  7. %PNBJO.PEFMT

  8. 0QFSBUJPO $BNQBJHO Ωϟϯϖʔϯɺ഑৴ͷ୯Ґ $BNQBJHO1FSJPE Ωϟϯϖʔϯͷ഑৴ظؒ #PPLJOH $BNQBJHOͱ1SPEVDUͷؔ࿈ςʔϒϧ 1SPEVDU ഑৴ର৅ͷ޿ࠂ࿮ 1MBDFNFOU

    ෳ਺ͷ1SPEVDUͷू߹ମ $SFBUJWF ΫϦΤΠςΟϒɺը૾΍λά $MJFOU ड஫ઌͷΫϥΠΞϯτ
  9. 0QFSBUJPO$BNQBJHO

  10. 0QFSBUJPO$SFBUJWFT

  11. 0QFSBUJPO $BNQBJHO 1FSJPE #PPLJOH 1MBDFNFOU $MJFOU $BNQBJHO 1SPEVDU 0SHBOJ[BUJPO $SFBUJWF

    0SEFS
  12. %FMJWFSZ %FMJWFSZ1MBO Ωϟϯϖʔϯ͝ͱͷྲྀྔΛهड़ͨ͠഑৴ܭը %FMJWFSZ1BZMPBE ഑৴͢Δ+40/1BZMPBET (PBM#VEHFUFE $1$࠷దԽܕ (PBM1FSDFOUBHF ഑৴ൺ཰ϕʔε (PBM*NQSFTTJPO

    ໨ඪ*NQSFTTJPOೖߘܕ (PBM$MJDL ໨ඪ$MJDLೖߘܕ (PBM3FNOBOU ༨৒ࡏݿ഑৴ܕ
  13. %FMJWFSZ%FMJWFSZ1MBO { "version": 1, "site_id": 3, "product_id": 537, "product_capacity": 1,

    "campaigns": [ { "id": 18585, "goal_type": "percentage", "creatives": [ { "id": 60057, "formats": [ "category_hijack_spw_with_image" ], "targets": [ { "keywords": [ "͘Ζ·Ί", "ΫϩϚϝ" ] } ] } ], "rate_numerator": 10000, "rate_denominator": 10000 },
  14. %FMJWFSZ%FMJWFSZ1BZMPBE [ { "key": "cookpad-android-search-master", "creatives": [ [ { "id":

    111, "template": "image", "click_url": "https://...", "media": { "mime_type": "image/jpeg", "original": "https://example.com/d6663ab44a0c48a1996debc690893493.jpg?1510564210", "width": 300, "height": 250 } } ] ] }
  15. 5BSHFUJOH $SFBUJWF ʢ࠶ܝʣ $SFBUJWF5BSHFU λʔήςΟϯάϧʔϧΛද͢ந৅Ϟσϧ "SFB3VMF ΤϦΞผλʔήςΟϯά "VEJFODF3VMF ηάϝϯτผλʔήςΟϯά ,FZXPSE3VMF

    ݕࡧΩʔϫʔυผλʔήςΟϯά 3FDJQF3VMF ϨγϐผλʔήςΟϯά 4DIFEVMF3VMF ༵೔ɾ࣌ؒଳผλʔήςΟϯά
  16. 5BSHFUJOH $SFBUJWF $SFBUJWF 5BSHFU ,FZXPSE 3VMF 3FDJQF 3VMF 4DIFEVMF 3VMF

    "SFB 3VMF "VEJFODF 3VMF
  17. +BWB4DSJQU4%, EJTQMBZKT

  18. EJTQMBZKT'FBUVSFT • Request to the ads delivery server • Parse

    response & build creative tags • Header Bidding wrapper • Logging for viewable impressions
  19. EJTQMBZKT-JCSBSJFT • webpack for building • babel for compile •

    eslint for static analysis • eslint-plugin-compat (<- one of maintainers #) • karma / jasmine • pupetter as an emulator • istanbul for coverage
  20. EJTQMBZKT3FRVFTU3FTQPOTF $ curl --globoff ‘https://example-ads.com/display?slots[pc-top-panel-main][capacity]=1' | jq . { "slots":

    [ { "key": "pc-top-panel-main", "creatives": [ [ { "id": 62596, "template": "image", "media": { "mime_type": "image/jpeg", "original": "https://img5-ak.cpcdn.com/ad4/19584ec3bf844581a0cfd1917cd785d8.jpg?1535448767", "width": 300, "height": 600, "center_crop": false } } ]
  21. 3FTQPOTFKT EJTQMBZKTBSDIJUFDUVSF $SFBUJWFKT 4MPUKT 3FRVFTUKT 1BZMPBEKT )FBEFS#JEEJOH )FBEFS#JEEJOH 8SBQQFSKT -PHHJOH

    -PHHFSKT -PH3FDPSEKT -PHHFS$MJFOUKT
  22. EJTQMBZKT)FBEFS#JEEJOH

  23. IUUQTUFDIMJGFDPPLQBEDPNFOUSZ .PSF%FUBJMT

  24. WT-FHBDZ

  25. ϨΨγʔΞʔΩςΫνϟ wϝϯόʔ͕େ͖͘มΘΓҾ͖ܧ͗ࠔ೉ w ݱঢ়ͷίʔυͱHJUCMBNFHJUMPH w ࣾ಺ʹ͸Կਓ͔౰࣌ͷϝϯόʔ͕͍Δ͜ͱ͸·ͩٹ͍ wزଟ΋ͷ7FSTJPOJOH w ೖߘϩδοΫɺ഑৴ϩδοΫɺλʔήςΟϯάϩδοΫɺ 4%,7FSTJPO͢΂ͯಠཱͯ͠਺ੈ୅ଘࡏ͢Δ

    wػೳ։ൃ༏ઌɺϦΞʔΩςΫνϟઐ໳͸ෆࡏ w ϧʔϧͰ஍ಓʹย෇͚͍ͯͬͨ
  26. ϨΨγʔͱͷઓ͍ํ wlௐࠪతϦϑΝΫλϦϯάzʹΑΔʮཧղʯ w ʰϨΨγʔιϑτ΢ΣΞվળΨΠυʱ wςετʹΑΔʮ඼࣭ʯͷݟ͑ΔԽ w ʰ૊৫ʹςετΛॻ͘จԽΛࠜ෇͔ͤΔઓུͱઓज़ʱ CZ!U@XBEB͞Μ wϦϑΝΫλϦϯάͷʮٕज़ʯΛ਎ʹ͚ͭΔ w

    ʢ࣍ܝʣ
  27. ϦϑΝΫλϦϯάͷʮٕज़ʯͱ͸ ۜͷ஄ؙ͸ͳ͍ɺ஍ಓͳٕज़ͷੵΈॏͶ w3FBEBCJMJUZ w ʰ5IF"SUPG3FBEBCMF$PEFʱ wσβΠϯύλʔϯ w ʰ(BNF1SPHSBNNJOH1BUUFSOTʱ wΦϒδΣΫτࢦ޲ઃܭ w

    ʰΦϒδΣΫτࢦ޲ઃܭ࣮ફΨΠυʱ w FUD
  28. ϦϑΝΫλϦϯάͷʮελϯεʯ wطଘͷίʔυϕʔε΁ͷʮଚܟʯ w ࠓͷձࣾͷച্Λ࡞ͬͨڝ૪ྗͷݯઘ wʮ͋Δ΂͖࢟ʯ͔Βߟ͑Δ w ൑அࡐྉʜࠓٻΊΒΕΔ࢓༷ɺϝϯόʔͷٕज़ϨϕϧɺӨڹ ൣғͱϦεΫ w໨తͱखஈΛࠞಉ͠ͳ͍ w

    αʔϏεͷ੒௕ΛՃ଎ͤ͞ɺ඼࣭ΛߴΊΔͨΊ w ಈతݴޠܕ੩తղੳ$*ʜશͯ͸खஈ
  29. ਖ਼͍͠ίετ൑அΛ͢Δ ख౰ͨΓ࣍ୈʹ௚͞ͳ͍ɻ lࠓ೔Կ΋͠ͳ͍͜ͱͷɺ কདྷతͳίετ͸ͲΕ͚ͩ ͩΖ͏ʁz ʰΦϒδΣΫτࢦ޲ઃܭ ࣮ફΨΠυʱQ

  30. $IBMMFOHFT

  31. ٕज़తνϟϨϯδ wνʔϜͷεϩʔΨϯͰ΋͋Δ wٕज़తνϟϨϯδΛ௨ͨ͡੒Ռˍ੒௕ wٕज़తνϟϨϯδΛ͠ͳ͍ͱރΕͯ͠·͏ wΩϟϦΞҎલʹਫ਼ਆӴੜ্ඞཁ w؆୯ʹͰ͖Δ΋ͷ͸zνϟϨϯδzͰ͸ͳ͍ wࣗ෼ͷݶք஋Λ্͛ΔӦΈ

  32. ԿΛʮνϟϨϯδʯ͢Δ͔ ʮ৽͍ٕ͠ज़ʯ͚͕ͩνϟϨϯδͰ͸ͳ͍ w ࣅͨΑ͏ͳϑϨʔϜϫʔΫΛ࢖ͬͨ͜ͱ͕͋Ε͹ɺֶͼ͸ ࣮͸গͳ͍ʢ͔΋͠Εͳ͍ʣ w ߴ඼࣭Λ࣮ݱ͢ΔͨΊͷϦΞʔΩςΫνϟɺίεύͷྑ͍ ςετɺγϡϛϨʔγϣϯ΍౷߹ςετͷ࢓૊Έɺϩάʹ ΑΔՄࢹԽɺೲظతͳνϟϨϯδ

  33. ຖ೔ͷྉཧΛָ͠Έʹ͢Δ 5IBOLZPV