見せてやろう…!! Serverlessの本当の力を…!! / Let’s show you the real power of serverless…!!

5cd1b99b9950b26e8ee005bd6cd1a860?s=47 Masashi Terui
February 23, 2019

見せてやろう…!! Serverlessの本当の力を…!! / Let’s show you the real power of serverless…!!

5cd1b99b9950b26e8ee005bd6cd1a860?s=128

Masashi Terui

February 23, 2019
Tweet

Transcript

  1. LET’S SHOW YOU THE REAL POWER OF SERVERLESS…!! ݟͤͯ΍Ζ͏…!! SERVERLESSͷຊ౰ͷྗΛ…!!

    MASASHI TERUI @ JAWS DAYS 2019
  2. SERVERWORKS CO.,LTD. + FREELANCER • @marcy_terui • JAWS Days 2015,2017,2018,2019

    speaker • Serverlessconf Tokyo 2016,2017,2018 speaker • Remote worker (in Sapporo-shi, Hokkaido) • The best Serverless Architect in Japan !!(Ͱ͋Γ͍ͨʣ MASASHI TERUI ARCHITECT / DEVELOPER
  3. SERVERLESS × EVENT DRIVEN ͦͷؔ܎͸ʁ

  4. SERVERLESS ARCHITECTURES (MARTINFOWLER.COM) “In the original version, all flow, control,

    and security was managed by the central server application. In the Serverless version there is no central arbiter of these concerns. Instead we see a preference for choreography over orchestration, with each component playing a more architecturally aware role—an idea also common in a microservices approach.” https://martinfowler.com/articles/serverless.html
  5. • ϝοηʔδϯά • ಉظ/ඇಉظ • Interactive/PubSub • σʔλετΞ • εέʔϦϯά

    • σʔλΞΫηε • ࣮ߦํ๏ • ฒྻ/௚ྻ • ܾఆత/ඇܾఆత ໨తΛՌͨͨ͢Ίͷ࠷దղ͸ҟͳΔ
  6. • ಉظ • API Gateway • ඇಉظ • ௚ྻ •

    Kinesis Streams • ฒྻ • SNS • SQS • ͦͷଞ • Step Functions ͲͷΑ͏ʹॲཧ͢΂͖͔ʁ
  7. EVENT DRIVEN ARCHITECTURE https://www.slideshare.net/AmazonWebServices/ building-massively-parallel-eventdriven- architectures-srv373r1-aws-reinvent-2018

  8. Event Source + Function = Microservice ʓʓ͕ى͖ͨΒ☓☓͢Δɺશͯ͸ͦͷ૊Έ߹Θͤ

  9. • ґଘؔ܎ͷ޲͖Λἧ͑Δ • Event SourceΛू໿఺ɾ෼ذ఺ͱ͢Δ • ෳࡶԽͷݪҼ͸େ఍σʔλΞΫηεʹ͋Δ • ॻ͖ࠐΈͱࢀরؔ܎ͷෳࡶԽ •

    σʔλͷॴ༗ؔ܎ • CQRS, Materialized View ෳࡶԽͤ͞ͳ͍ͨΊʹ
  10. • ॻ͖ࠐΈͱಡΈࠐΈͰಉ͡σʔλΛѻ͏ඞཁ͸ͳ͍ • ॻ͖ࠐΈͷݪ୯ҐΛߟ͑ɺΞΠςϜʹ·ͱΊΔ͜ͱͰ੔߹ੑΛकΔ • DynamoDB Transactionͷొ৔Ͱ͍ͩͿָʹͳͬͨ • ಡΈࠐΈ͸݁Ռ੔߹Λड͚ೖΕͯޮ཰ͷྑ͍σʔλΛੜ੒͍ͯ͘͠ •

    Ͱ͖ΔݶΓҰͭͷFunction͕ѻ͏΂͖σʔλΛҰͭͱ͢Δ • Write͸ൺֱత؆୯ • Read͸CQRS, Materialized ViewΛ্ख͘࢖͏ Data Modeling
  11. DATA ATOMICITY MicroserviesతͳΠϝʔδͰ͸͜ͷݪ୯Ґ͕ॏཁ σʔλετΞɾςʔϒϧͷ෼͚ํͰ͸ͳ͍ ލ͕͍ͤͨͳΒMaterialized ViewΛ࡞Δ User Profile User Status

    Name Email Read/Write Search Read/Write
  12. Ͳ͏ઃܭ͢Ε͹ྑ͍ͷ͔ʁ ͜͏͍ͬͨ͜ͱΛ্ख͘΍ΔͨΊʹ

  13. ඇಉظΛϕʔεʹߟ͑Δ ࢦࣔͨ͠ΒऴΘΔ·ͰԿ΋ͤͣʹ଴ͬͯΔͳΒࣗ෼(MONOLITH)Ͱ΍Ε͹ྑ͍ͷͰ͸ʁ

  14. EVENT ROUTING https://www.slideshare.net/AmazonWebServices/ building-massively-parallel-eventdriven- architectures-srv373r1-aws-reinvent-2018

  15. • Request <-> Responseͱ͍͏ґଘؔ܎Λ੾Γ཭ͤΔ • ಠཱੑ͕ߴ·Δ • ґଘؔ܎ͷ޲͖͕ἧ͑΍͘͢ͳΔ • εϧʔϓοτΛίϯτϩʔϧ͠΍͘͢ͳΔ

    • ݁Ռతʹอकੑɾӡ༻ੑ͕ߴ·Δ ඇಉظॲཧͷԿ͕خ͍͔͠
  16. • ͭ·ΔॴΤϥʔϋϯυϦϯά • ϦτϥΠՄೳͳΤϥʔ͸ϦτϥΠ͢Δ • ϦτϥΠ͠΍͍͢ͷ͸ඇಉظͷར఺Ͱ͸͋Δ • ϦτϥΠͰ͖ͳ͍ΤϥʔΛͲ͏͢Δʁʁ • ͋ͱϞχλϦϯάɾτϨʔγϯά

    • ඞཁͳ৘ใ͸ू໿͢Δ • ࠓ೔͸จ຺ζϨΔͷͰ͓·͚ʢ͕࣌ؒ͋ͬͨΒʣ ඇಉظॲཧʹ͓͚Δෆ҆
  17. DEMO https://github.com/marcy-terui/jawsdays-2019-demo

  18. ࠓ·Ͱᶃ ಉظAPIͰαʔϏε෼ׂ ͭΒ͍ ஫จॲཧ ܾࡁαʔϏε ࡏݿαʔϏε ϝʔϧαʔϏε

  19. ࠓ·Ͱᶄ ඇಉظ + ϙʔϦϯάͰؤுΔ ۀ຿ϩδοΫ͸γϯϓϧʹͳΔ൓໘ΞʔΩςΫνϟ͕ෳࡶ ஫จॲཧ ܾࡁαʔϏε ࡏݿαʔϏε ϝʔϧαʔϏε ݁ՌΛू໿

    ݁Ռ֬ೝ
  20. ͜Ε͔Β ཧ૝తʹγϯϓϧͳඇಉظॲཧʹΑΔ αʔϏε෼ׂ ݁ՌΛͦΕͧΕ͕ ௚઀ΫϥΠΞϯτ΁ฦ͢

  21. WebSocket API Gateway͸ ͨͩͷManaged WebSocket EndpointͰ͸ͳ͍

  22. • ઀ଓʹରͯ͠ҰҙͷConnection ID͕ৼΒΕΔ • ͜ͷIDΛ࢖ͬͯ؅ཧAPIʹσʔλΛ౤͛Δͱ
 Ͳ͔͜ΒͰ΋೚ҙͷΫϥΠΞϯτʹσʔλΛ౤͛ΒΕΔ • ඇಉظͷEvent࿈ܞͰConnection IDΛҾ͖ճͤ͹
 ్தͰམͪͯ΋ClientʹΤϥʔΛฦͤΔ

    WebSocket API Gateway
  23. Τϥʔॲཧ͚ͩ͡Όͳ͍

  24. ͜͏͍͏ͷ΋ ෳ਺ͷαʔϏε͔ΒσʔλΛ ͔͖ूΊͯ͘Δ΍ʔͭ

  25. ͜͏Ͱ͖Δ ͦΕͧΕͷαʔϏε͔Β ௚઀σʔλΛฦͤ͞Δ

  26. ͞ΒʹAppSyncΛՃ͑Δͱ

  27. ࡞Εͦ͏ͳؾ͕͢Δ ཧ૝తͳEvent Sourcing, CQRSͳ Microservices Architecture ΫϥΠΞϯτ΁݁ՌΛฦ͢ॴ͸লུ ʢਤ͕ෳࡶʹͳΔͷͰʣ

  28. • Lambda͔Β࢖͍ͮΒ͍ • AmplifyͷAppSync ClientͷServer Side޲͚ʢͱଞݴޠ൛ʣ΄͍͠ • ೝূΛUser Pool΍OIDCʢͱҰԠAPI Keyʣʹͯ͠΋


    Lambda͔Β͸IAMͰೝূͤͯ͞΄͍͠ • Amplify CLI͔ΒDynamoDB Table࡞Δͱςʔϒϧ໊͕ಛఆͰ͖ͳ͍ • AppSync௨ͤͬͯ͜ͱͳΜͩΖ͏͚ͲͦΕͳΒLambda͔Βʢ͈́ • DynamoDBͷมߋΛࣗಈͰΩϟϓνϟͯ͠SubscriptionൃՐͯ͠΄͍͠ Ͱ΋AppSyncૉఢ͚ͩͲͪΐͬͱ଍Γͳ͍
  29. ϞχλϦϯάɾτϨʔγϯά(͓·͚)

  30. • ࣮ࡍʹ໰୊͕ى͖ͨ(ى͖ͦ͏)͜ͱΛ؂ࢹ͢Δ • Τϥʔͷൃੜ΍஗ԆΛ؂ࢹ͢Δ • API Gateway: Latency, 5XX Response

    • Lambda: Duration, Errors, Throttling, DeadLetterErrors • DynamoDB: Consumed Capacity, Throttling, Latency, Errors
 •Ұ൪େ੾ͳͷ͸ΞϓϦέʔγϣϯͷϩά ϞχλϦϯά
  31. • DeadLetterErrors • ͿͬͪΌ͚LambdaͷىಈError͸ى͖Δ࣌͸ͪΐ͍ͪΐ͍ى͖Δ • ࠶࣮ߦͰ্ख͘ݴͬͯΔέʔε͕΄ͱΜͲ • ࠶࣮ߦ΋ࣦഊͯ͠औΓ͜΅ͨ͠Error͸͜ΕΛݟͳ͍ͱ෼͔Βͳ͍(ཁઃఆ) • Throttling

    • SDK͸Throttlingͯ͠΋಺෦Ͱউखʹ࠶࣮ߦ͢Δ • Τϥʔ͕ى͖ͯͳ͍͔ΒThrottling͕ى͖ͯͳ͍ͱ͸ݶΒͳ͍ • ͜ΕΛݟΔͱൃੜঢ়گ͕෼͔ΔˠCapacity௥Ճ ؂ࢹ߲໨ྫ
  32. • ෼ࢄͨ͠FaaS؀ڥͰ͸͍͔ʹू໿ͯ͠ޮ཰Α͘ݟΒΕΔΑ͏ʹ͢Δ͔͕େࣄ • ·ͣू໿͢Δͷ͸େલఏ • CloudWatch Logs͸ͨͩͷόοΫΞοϓ • Kinesis Firehose

    -> Elasticsearch • Datadog LogsΦεεϝ • https://github.com/marcy-terui/ddlogs • Trace IDͷड͚౉͠ํΛܾΊͯԣ۲ͰݕࡧͰ͖ΔΑ͏ʹ͢Δ τϨʔγϯά
  33. LOGS WITH TRACE ID Datadog Logsͷ࣮ࡍͷը໘Ͱ͢

  34. • Serverless͸Event Drivenͱ૬ੑ͕ྑ͍ • ඇಉظओମʹઃܭ͢Δ͜ͱͰґଘੑͱಠཱੑΛߴΊΒΕΔ • ඇಉظॲཧΛ্ख͘੔ཧ͢Δͷʹ΋Event Drivenͱ͍͏ߟ͑ํ͕༗ޮ • Serverlessͳඇಉظॲཧʹ͓͚Δෆ҆ཁૉ͸෷১͞Εͨ

    • WebSocket API Gateway͸
 ͨͩͷManaged WebSocket EndpointͰ͸ͳ͍ • AppSync͸ະདྷʢ͋ͱ΋͏ͪΐͬͱɾɾɾʂʣ • ཧ૝ͷΞʔΩςΫνϟ΁ͷಓ͕ݟ͖͑ͯͨ SUMMARY
  35. 2019೥͸SERVERLESSͷ೥ͩʂʂ THANKS!!