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

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

Masashi Terui
February 23, 2019

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

Masashi Terui

February 23, 2019
Tweet

More Decks by Masashi Terui

Other Decks in Technology

Transcript

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

    View full-size slide

  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

    View full-size slide

  3. SERVERLESS × EVENT DRIVEN
    ͦͷؔ܎͸ʁ

    View full-size slide

  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

    View full-size slide

  5. • ϝοηʔδϯά
    • ಉظ/ඇಉظ
    • Interactive/PubSub
    • σʔλετΞ
    • εέʔϦϯά
    • σʔλΞΫηε
    • ࣮ߦํ๏
    • ฒྻ/௚ྻ
    • ܾఆత/ඇܾఆత
    ໨తΛՌͨͨ͢Ίͷ࠷దղ͸ҟͳΔ

    View full-size slide

  6. • ಉظ
    • API Gateway
    • ඇಉظ
    • ௚ྻ
    • Kinesis Streams
    • ฒྻ
    • SNS
    • SQS
    • ͦͷଞ
    • Step Functions
    ͲͷΑ͏ʹॲཧ͢΂͖͔ʁ

    View full-size slide

  7. EVENT DRIVEN ARCHITECTURE https://www.slideshare.net/AmazonWebServices/
    building-massively-parallel-eventdriven-
    architectures-srv373r1-aws-reinvent-2018

    View full-size slide

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

    View full-size slide

  9. • ґଘؔ܎ͷ޲͖Λἧ͑Δ
    • Event SourceΛू໿఺ɾ෼ذ఺ͱ͢Δ
    • ෳࡶԽͷݪҼ͸େ఍σʔλΞΫηεʹ͋Δ
    • ॻ͖ࠐΈͱࢀরؔ܎ͷෳࡶԽ
    • σʔλͷॴ༗ؔ܎
    • CQRS, Materialized View
    ෳࡶԽͤ͞ͳ͍ͨΊʹ

    View full-size slide

  10. • ॻ͖ࠐΈͱಡΈࠐΈͰಉ͡σʔλΛѻ͏ඞཁ͸ͳ͍
    • ॻ͖ࠐΈͷݪ୯ҐΛߟ͑ɺΞΠςϜʹ·ͱΊΔ͜ͱͰ੔߹ੑΛकΔ
    • DynamoDB Transactionͷొ৔Ͱ͍ͩͿָʹͳͬͨ
    • ಡΈࠐΈ͸݁Ռ੔߹Λड͚ೖΕͯޮ཰ͷྑ͍σʔλΛੜ੒͍ͯ͘͠
    • Ͱ͖ΔݶΓҰͭͷFunction͕ѻ͏΂͖σʔλΛҰͭͱ͢Δ
    • Write͸ൺֱత؆୯
    • Read͸CQRS, Materialized ViewΛ্ख͘࢖͏
    Data Modeling

    View full-size slide

  11. DATA ATOMICITY MicroserviesతͳΠϝʔδͰ͸͜ͷݪ୯Ґ͕ॏཁ
    σʔλετΞɾςʔϒϧͷ෼͚ํͰ͸ͳ͍
    ލ͕͍ͤͨͳΒMaterialized ViewΛ࡞Δ
    User
    Profile
    User
    Status
    Name Email
    Read/Write
    Search
    Read/Write

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  15. • Request <-> Responseͱ͍͏ґଘؔ܎Λ੾Γ཭ͤΔ
    • ಠཱੑ͕ߴ·Δ
    • ґଘؔ܎ͷ޲͖͕ἧ͑΍͘͢ͳΔ
    • εϧʔϓοτΛίϯτϩʔϧ͠΍͘͢ͳΔ
    • ݁Ռతʹอकੑɾӡ༻ੑ͕ߴ·Δ
    ඇಉظॲཧͷԿ͕خ͍͔͠

    View full-size slide

  16. • ͭ·ΔॴΤϥʔϋϯυϦϯά
    • ϦτϥΠՄೳͳΤϥʔ͸ϦτϥΠ͢Δ
    • ϦτϥΠ͠΍͍͢ͷ͸ඇಉظͷར఺Ͱ͸͋Δ
    • ϦτϥΠͰ͖ͳ͍ΤϥʔΛͲ͏͢Δʁʁ
    • ͋ͱϞχλϦϯάɾτϨʔγϯά
    • ඞཁͳ৘ใ͸ू໿͢Δ
    • ࠓ೔͸จ຺ζϨΔͷͰ͓·͚ʢ͕࣌ؒ͋ͬͨΒʣ
    ඇಉظॲཧʹ͓͚Δෆ҆

    View full-size slide

  17. DEMO
    https://github.com/marcy-terui/jawsdays-2019-demo

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  22. • ઀ଓʹରͯ͠ҰҙͷConnection ID͕ৼΒΕΔ
    • ͜ͷIDΛ࢖ͬͯ؅ཧAPIʹσʔλΛ౤͛Δͱ

    Ͳ͔͜ΒͰ΋೚ҙͷΫϥΠΞϯτʹσʔλΛ౤͛ΒΕΔ
    • ඇಉظͷEvent࿈ܞͰConnection IDΛҾ͖ճͤ͹

    ్தͰམͪͯ΋ClientʹΤϥʔΛฦͤΔ
    WebSocket API Gateway

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  26. ͞ΒʹAppSyncΛՃ͑Δͱ

    View full-size slide

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

    View full-size slide

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

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

    View full-size slide

  29. ϞχλϦϯάɾτϨʔγϯά(͓·͚)

    View full-size slide

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

    •Ұ൪େ੾ͳͷ͸ΞϓϦέʔγϣϯͷϩά
    ϞχλϦϯά

    View full-size slide

  31. • DeadLetterErrors
    • ͿͬͪΌ͚LambdaͷىಈError͸ى͖Δ࣌͸ͪΐ͍ͪΐ͍ى͖Δ
    • ࠶࣮ߦͰ্ख͘ݴͬͯΔέʔε͕΄ͱΜͲ
    • ࠶࣮ߦ΋ࣦഊͯ͠औΓ͜΅ͨ͠Error͸͜ΕΛݟͳ͍ͱ෼͔Βͳ͍(ཁઃఆ)
    • Throttling
    • SDK͸Throttlingͯ͠΋಺෦Ͱউखʹ࠶࣮ߦ͢Δ
    • Τϥʔ͕ى͖ͯͳ͍͔ΒThrottling͕ى͖ͯͳ͍ͱ͸ݶΒͳ͍
    • ͜ΕΛݟΔͱൃੜঢ়گ͕෼͔ΔˠCapacity௥Ճ
    ؂ࢹ߲໨ྫ

    View full-size slide

  32. • ෼ࢄͨ͠FaaS؀ڥͰ͸͍͔ʹू໿ͯ͠ޮ཰Α͘ݟΒΕΔΑ͏ʹ͢Δ͔͕େࣄ
    • ·ͣू໿͢Δͷ͸େલఏ
    • CloudWatch Logs͸ͨͩͷόοΫΞοϓ
    • Kinesis Firehose -> Elasticsearch
    • Datadog LogsΦεεϝ
    • https://github.com/marcy-terui/ddlogs
    • Trace IDͷड͚౉͠ํΛܾΊͯԣ۲ͰݕࡧͰ͖ΔΑ͏ʹ͢Δ
    τϨʔγϯά

    View full-size slide

  33. LOGS WITH TRACE ID Datadog Logsͷ࣮ࡍͷը໘Ͱ͢

    View full-size slide

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

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

    View full-size slide

  35. 2019೥͸SERVERLESSͷ೥ͩʂʂ
    THANKS!!

    View full-size slide