何故私達はサーバレスアプリケーションをイベントドリブンで作るべきなのか / Why should we make serverless application as event driven?

何故私達はサーバレスアプリケーションをイベントドリブンで作るべきなのか / Why should we make serverless application as event driven?

5cd1b99b9950b26e8ee005bd6cd1a860?s=128

Masashi Terui

May 24, 2018
Tweet

Transcript

  1. WHY SHOULD WE MAKE SERVERLESS APPLICATION AS EVENT DRIVEN? MASASHI

    TERUI @ SAPPORO.AWS #2
  2. SERVERWORKS CO.,LTD. + FREELANCER • Serverless Oji-san • Serverless Framework

    Plugin Developer • Serverlessconf Tokyo 2016/2017 speaker • Remote worker (in Sapporo) • The best Cloud Engineer in Hokkaido!! (Ͱ͋Γ͍ͨʣ MASASHI TERUI ARCHITECT / DEVELOPER
  3. SERVERLESSͬͯͳΜ͚ͩͬʁ WHAT IS

  4. CNCF SERVERLESS WHITEPAPER V1.0 • Serverless computing refers to the

    concept of building and running applications that do not require server management • A platform may provide one or both of the following: • Functions-as-a-Service (FaaS) • Backend-as-a-Service (BaaS) • Products or platforms deliver the following benefits to developers: • Zero Server Ops • No Compute Cost When Idle 
 https://github.com/cncf/wg-serverless/tree/master/whitepaper
  5. SERVERLESS CLOUD NATIVE LANDSCAPE

  6. ͬͪ͜ͷํ͕෼͔Γ΍͍͢͠޷͖ https://www.slideshare.net/acloudguru/ant-stanley-being-serverless

  7. SERVERLESS USE CASES (FROM CNCF WP) • Asynchronous, concurrent, easy

    to parallelize into independent units of work • Infrequent or has sporadic demand, with large, unpredictable variance in scaling requirements • Stateless, ephemeral, without a major need for instantaneous cold start time • Highly dynamic in terms of changing business requirements that drive a need for accelerated developer velocity • Non-HTTP-centric and non-elastic scale workloads that weren’t good fits for an IaaS, PaaS, or CaaS solution
  8. ͔͠͠ɺ͋ΔServerlessաܹ೿͸ݴ͍·ͨ͠ https://speakerdeck.com/toricls/how-serverless-loves-event-driven-architecture “Event Driven͕ͦ͜ServerlessͦΕҎ֎͸ೝΊΜʂ” ※٭৭͕͋Γ·͢

  9. EVENT DRIVENͬͯԿ͕ඒຯ͍͠ͷʁ

  10. MICROSERVICESͱฉ͍ͯԿΛࢥ͍ු͔΂·͔͢ʁ

  11. ͜ΕͰ͸ʁ https://www.slideshare.net/apigee/is-microservices-soa-done-right

  12. ΈΜͳMicroservicesͬͯ͜͏͍͏ͷͩͱࢥ͍͕ͪ ґଘؔ܎͕ෳࡶɺ؅ཧ͕೉͍͠ɺ࡞Δͷ΋೉͍͠ େن໛޲͚Ͱ͔͠ͳ͍

  13. Event Drivenʹ͢Δͱ͜͏ͳΔ ґଘؔ܎Λૄʹอͪͭͭू໿ɺ੔ཧͰ͖Δ ن໛Λ໰Θͣཧ૝తͳΞʔΩςΫνϟΛऔΓ΍͍͢

  14. ΋͏͢͜͠ৄ͘͠ • Pub/Subͷؔ܎ • Publisher͸ൃߦ͢΂͖Πϕϯτ͚ͩΛ஌͍ͬͯΔ • Subscriber͸ߪಡ͢΂͖Πϕϯτ͚ͩΛ஌͍ͬͯΔ • ґଘؔ܎ΛૄͰ͋Γͳ͕Βू໿ɺ੔ཧͰ͖Δ •

    ͜ͷؔ܎͸ٯస͠ͳ͍ͨΊɺྲྀΕ͕෼͔Γ΍͘͢ͳΔ • ࣗવͱඇಉظʹͳΔ • ඇಉظͰ͋Δͱ͍͏͜ͱ͸ϦτϥΠՄೳͰ͋Δͱ͍͏͜ͱ
  15. EVENT DRIVENͬͯͲ͏΍Δͷʁ

  16. େ͖͘෼͚Δͱ͔̎ͭ͠ͳ͍ Pull Push

  17. ࢖͍෼͚ - Pull • େྔͷΠϕϯτΛϋϯυϦϯά͍ͨ͠ • ࣮֬ʹॲཧ͍ͨ͠ɺࣦഊ͢Δ֬཰͕ൺֱతߴΊ • ϦτϥΠճ਺ɾظؒΛ௕͘औΕΔ •

    ಉ࣮࣌ߦ਺΍ฒྻ౓Λίϯτϩʔϧ͍ͨ͠ • DBॻ͖ࠐΈͱ͔֎෦αʔϏεݺͼग़͠ͱ͔
  18. ࢖͍෼͚ - Push • ஗ԆΛͰ͖Δ͚ͩগͳ͘ॲཧ͍ͤͨ͞ • ฒྻ౓Λ্͍͛ͨ • Ұ౓ʹଟ͘ͷॲཧΛىಈ͍ͨ͠ •

    ϦτϥΠػߏ͸͋ΔͷͰجຊ͸ͬͪ͜Ͱߟ͑Δ • ̏ճϦτϥΠˠDLQ
  19. AWSαʔϏεͷ࢖͍෼͚

  20. Kinesis Streams • PullܕΠϕϯτιʔεͷ୅ද֨ • େྔͷΠϕϯτΛόοϑΝͰ͖Δ • ॱংอূ͕͋Δ • ͨͩ͠ɺ͋ΒΏΔ৚݅ͰॱংΛҡ࣋͠Α͏ͱ͢Δͱ


    ॲཧΛࢭΊ͟ΔΛಘͳ͘ͳΔ • Ͱ͖Δ͚ͩॱংอূ͠ͳ͍ͰࡁΉΑ͏ʹ΂͖౳ʹઃܭ͢Δ
  21. Simple Queue Service (SQS) • ϙʔϦϯά͕ඞཁʹͳΔͨΊਖ਼௚͋·Γ࢖Θͳ͍ʢࢲ͸ʣ • KinesisͰࣦഊͨ͠ΠϕϯτΛPut͠௚ͤ͹ྑ͍͡ΌΜతͳ • PushܕͰ΋DLQ͋Δ͠తͳ

  22. Simple Nortification Service (SNS) • PushܕΠϕϯτιʔεͷ୅ද֨ • 1:NͷN͕ଟ͘ͳΔέʔεʹڧ͍ (Fanout) •

    ͚ͬ͜͏୔ࢁ࢖͏ͷͰ
 Serverless Frameworkͱ͔࢖Θͳ͍ͱઃఆ͕͠ΜͲ͍
  23. Step Functions • Push͕਺चͭͳ͗ʹͳΔ࣌ͷϋϯυϦϯά͕ΊͬͪΌศར • ֎෦ೖྗ଴ͪͰϙʔϦϯάͤ͟ΔΛಘͳ͍৔߹ʹ΋ • State Machine DataʹσʔλΛڞ༗Ͱ͖Δͷศར

    • ؾΛൈ͘ͱશ෦͜ΕͰ΍Γͨ͘ͳΔ
  24. API Gateway • جຊతʹ֎෦ΠϕϯτΛड͚औΔޱͱߟ͑Δ • ReadܥͳͲ݁Ռ͕ඞཁͰಉظͰॲཧ͢Δ৔߹ʹ಺෦Ͱ࢖͏ • ͨͩ͠1Πϕϯτ1ίʔϧ(Read)Λ৺͕͚Δ • ෳ਺ͷίʔϧ(Read)͕ඞཁͳ৔߹͸SNSͰFanout


    ·ͨ͸Step FunctionsΛ࢖͏ͳͲͯ͠෼ղ͢Δ
  25. S3 Event Notification • ϖΠϩʔυͷେ͖ͳΠϕϯτΛѻ͏ • ϑΝΠϧͱͯ͠֎෦ೖྗΛΠϕϯτͱͯ͠ѻ͏

  26. CloudWatch Events • Event-based • AWSͷαʔϏεΛτϦΨʔͱ͢ΔΠϕϯτΛൃߦ͢Δ • Time-based • ࣌ؒΛτϦΨʔͱ͢ΔΠϕϯτΛൃߦ͢Δ

  27. ʢ͓·͚ʣLambda -> Lambda • جຊ΍Βͳ͍ʢࢲ͸ʣ • େମSNSڬΉ or ਺चܨ͗ʹͳΔͳΒStep FunctionsΛ࢖͏

    • 1:1͕100%อূͰ͖Δ৔߹ͷΈ࢖ͬͯ΋ྑ͍ʢ͔΋ʣ • Ͱ΋ͦΕ1FunctionͰྑ͍Μ͡Όɾɾɾ
  28. ALL BECOME EVENT DRIVEN

  29. Event Driven͡Όͳͯ͘΋ͪ͠Ό͑Δ

  30. THANKS!! LET’S ENJOY SERVERLESS
 WITH EVENT DRIVEN ARCHITECTURE !!