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

Scala: Mobile Backend on AWS

arai-yusuke
February 20, 2016

Scala: Mobile Backend on AWS

arai-yusuke

February 20, 2016
Tweet

More Decks by arai-yusuke

Other Decks in Technology

Transcript

  1. whoami • Yusuke Arai • Classmethod (2014/11~) • Mobile Backend

    API Team (2015/02~) • AWS / Scala / Javascript / android • dev.classmethod.jp/author/arai-yusuke
  2. ☓ LL࿩ऀͳΒೃછΈ΍͍͢ • Scala͸altJavaͱͯ͠΋ར༻Ͱ͖Δ͕
 ͦΕ͸"Scalaݴޠ"ʹݶͬͨ࿩ͰɺΤίγεςϜ͕ͦΕΛ
 ڐ͢ͱ͸ݶΒͳ͍ • Play Framework 2.4

    ͸ڧྗͳܕγεςϜΛ಺෦ʹ࣋ͪɺ
 ਵॴͰܕγεςϜ΁ͷཧղΛཁٻ͢Δɻ • ྫ: JsResult ͸ Applicative Functor
 Writes ͸ Contravariant Functor
  3. Scala Λ࢖͍͚ͬͯ͹…… • JVM΍Javaͷྺ࢙ʹ͍ͭͯਂ͘ཧղͰ͖Δ • ؔ਺ܕͷάουϓϥΫςΟε͕औΓࠐΊΔ • ܕΫϥεɺ୅਺తσʔλܕɺؔखɺϞφυ
 ͳͲͷమ൘ύλʔϯ͕࢖͑ΔΑ͏ʹͳΔ •

    ৽͠ΊͷݴޠͰ͸͍͍ͩͨˢ͕Ұ෦·ͨ͸શ෦࢖͑Δ
 ྫ͑͹Swiftʹ΋flatMapϝιου͕༻ҙ͞Ε͍ͯ·͢ • ৽͍͠ػೳΛ࢖͍͜ͳ͠඼࣭ͷߴ͍ΞϓϦΛ࡞Δ͜ͱ͕Մೳʹʂ

  4. ։ൃͷਐΊํ • ϑϧͰςετॻ͘
 ʢશΫϥεϢχοτςετɺAPIຖ࠷௿̍݁߹ςετʣ • pull reqϨϏϡʔඞਢ • Scalaz΍Cats͸࢖Θͳ͍ •

    ࠓϦϦʔεલͳͷͰύϑΥʔϚϯεɾӡ༻ʹ͍ͭͯͷ͜ͱ͸Կͱ΋ ݴ͑ͳ͍ʢϦϦʔεͰ͖͍ͯͨΒӡ༻ϊ΢ϋ΢Λ͓఻͔͑ͨͬͨ͠Ͱ͢……ʣ
  5. Akka • ࠓճ͸ϫʔΧʔΛAkka SchedulerͰ࣮૷ • AkkaͷFault ToleranceΛങͬͨ • Amazon SQS΍Amazon

    SNSͱ͏·݁͘߹͢Δ • DynamoDB Stream΍Kinesisͱ͚ͬͭͨ͘Β
 ઈରָ͍͠ͰΑ͢Ͷ
  6. AWS Java SDK͕࢖͑Δ • AWSͷϑϧϚωʔδυαʔϏεʢCognito΍DynamoDBʣ ͱ΍ΓऔΓ͢ΔΞϓϦΛ࡞Δ৔߹ɺ
 AWS SDKͷυΩϡϝϯςʔγϣϯ۩߹͸ࢮ׆໰୊ • AWS

    Java SDKʹ͸Կͷ৺഑΋ͳ͔ͬͨ • Scalaͷݴޠࢥ૝ͱͯ͠ʮmutable࣮૷ΛimmutableͳΠϯ λϑΣʔεͰӅṭʯͱ͍͏ͷ͕͋Δ
 ˠ AWS Java SDK ͸Πϯϑϥ૚ͰӅṭͰ͖ΔͷͰແ໰୊
  7. AWS Lambda ͕ओମ΁ • όοΫΤϯυʹ͋Δmicro services΁ͷ
 ΦʔέετϨʔγϣϯͰ͸ͳ͍ • υϝΠϯϩδοΫ͕AWS Lambda

    Functionͱ
 ͯ͠දݱ͞ΕΔαʔόʔϨεΞʔΩςΫνϟ • ୯Ґ͕ micro services ͔Β functions ΁
  8. Evolution of Compute – Public Cloud Infrastructure Instances Application code

    ©Amazon Web Services via http://www.slideshare.net/AmazonWebServices/arc308-the-serverless-company-using-aws-lambda/
  9. Evolution of Compute – Containers Infrastructure Instances Application code Containers

    ©Amazon Web Services via http://www.slideshare.net/AmazonWebServices/arc308-the-serverless-company-using-aws-lambda/
  10. Evolution of Compute – Serverless Application code ©Amazon Web Services

    via http://www.slideshare.net/AmazonWebServices/arc308-the-serverless-company-using-aws-lambda/
  11. Scala in AWS Lambda • Lambda͸ScalaͰॻ͚·͢ɻ͜Ε͸Scalaʹݶͬͨ࿩ Ͱ͸ͳ͘ɺJVMݴޠͳΒOKɻ • ͬ͟ͱࢼͨ͠ײ͡Ͱ͸ແཧ΍Γײ͕ͰΔ
 ͜ͱ΋ͳ͘ɺ͍͍ײ͡ʹॻ͚·͢ɻ

    • ٕज़ௐࠪΛਐΊ͍ͯͯɺ΋͏গ͠φϨοδ͕ཷ·Ε͹
 ͍ۙ͏ͪʹຊ൪ద༻ՄೳʹͳΓͦ͏ɻ ͜ͷลΓΛ۷ΓԼ͛Δ࿩Λ݄̑ʹ෱ԬͰ͠·͢ʂ
 ʲScala෱Ԭ2016ʳͰݕࡧݕࡧʂ
  12. ݱঢ়ͷࡉ͔͍Cons • Artifact ZIPʹ50MB੍ݶ͕͋Δ
 → ࡞ΓํΛ޻෉͢Δඞཁ͕͋Δ΋ͷͷɺ
 ɹ ϚΠΫϩαʔϏεͷߟ͑ํΛܧঝ͢ΔͳΒ͹
 ɹ ରॲՄೳͳ੍ݶ

    • JVMͷॳճىಈίετ͕Φʔόʔϔουʹʁ
 ˠ Lambda in VPCͳΒ͹ENIίετ΋͋ΔͷͰɺ
 ɹ ॳճ͸஗͍΋ͷͱׂΓ੾Δ
  13. ୅දతFramework • Ruby on Rails (Ruby) • Express (Node.js) •

    Laravel (PHP) • Play Framework (Java) • etc
  14. vs Rails, Node, PHP • Play-Scalaͱ͸໰୊ղܾͷϞσϧ͕͸͖ͬΓ
 ҧ͏ͷͰɺઆ໌ʢઆಘʣ͠΍͍͢ɻ • ଱ো֐ੑʢResiliencyʣ, ৳ॖੑʢElasticityʣ


    ৴པੑʢReliabilityʣͳͲͰѹউ͢Δɻ • ڧ͍ͯݴ͑͹1ΠϯελϯεͰC100Kͷޭ੷͕͋Δ Node͕Ұ൪ͷϥΠόϧɻ
  15. JVM

  16. ·ͱΊ • Scala͸ؔ਺ܕ΋Ͱ͖ΔOOPݴޠͰ͢Αʂ • དྷΔLambda Xσʔʹ͸ɺScala͸։ൃऀʹଟ͘ͷ޾ ͤΛ΋ͨΒ͢Ͱ͠ΐ͏ɻ • Resiliency, Elasticity,

    Reliability!! • ScalaΛ࢖͏ར఺Λ͔ͬ͠Γઆ໌্ͨ͠Ͱ
 “JavaͳΒ͹҆৺” ͱ͍͏ݬ૝ΛͿͪյ͢ʂ