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

はてなにおけるマイクロサービスとScala / Microservices and Scala...

aereal
October 08, 2016

はてなにおけるマイクロサービスとScala / Microservices and Scala at Hatena

Scala関西Summit 2016 (http://summit.scala-kansai.org/) の発表資料です。

aereal

October 08, 2016
Tweet

More Decks by aereal

Other Decks in Programming

Transcript

  1. ݱߦܾࡁγεςϜͷվम • ΄ͱΜͲݱ࣮తͰ͸ͳ͍ • ޓ׵ੑʹؔ͢ΔεΩʔϜ͕ͳ͍ • ׬શޙํޓ׵ or die •

    ෳ਺ͷυϝΠϯ͕ೖΓཚΕ͍ͯΔ • ݱࡏͷ࢓༷ʹӨڹΛڧ͘ड͚Δ • վળ͕·ΘΒͳ͍
  2. ׬

  3. ࣋ଓՄೳʹ࡞Γ (ͳ͓͠) ͍ͨ • είʔϓΛখ͘͞໌ྎʹอͭ • ૄ݁߹ (ʰϚΠΫϩαʔϏεΞʔΩςΫνϟʱ3.2.1) • ߴڽूੑ

    (ʰϚΠΫϩαʔϏεΞʔΩςΫνϟʱ3.2.2) • ෼ׂ౷࣏͢Δ • ٕज़ҟ࣭ੑ (͍ͭ·Ͱ΋Perl͸ݫ͍͠) • σϓϩΠͷϥΠϑαΠΫϧΛૣΊΔ
  4. ׬

  5. ඇػೳཁٻΛఆΊΔ • ISO 9126 • functionality: ػೳੑ • reliability: ৴པੑ

    • usability: ࢖༻ੑ • efficiency: ޮ཰ੑ • maintainability: อकੑ • portability: Ҡ২ੑ
  6. ඇػೳཁٻΛఆΊΔ • ISO 9126 • functionality: ػೳੑ • reliability: ৴པੑ

    • usability: ࢖༻ੑ • efficiency: ޮ཰ੑ • maintainability: อकੑ • portability: Ҡ২ੑ
  7. ঢ়ଶΛྻڍܕͰදݱ͢Δ sealed trait State object State { case object Requested

    extends State case object Paid extends State case object Failed extends State } ※࣮ࡍ͸΋͏ͪΐͬͱ͍Ζ͍Ζ͋Γ·͢
  8. ঢ়ଶΛྻڍܕͰදݱ͢Δ case class Payment(state: State) { def charged: Boolean =

    state match { case State.Paid => true case _ => false } }
  9. ׬

  10. ΤϯςΟςΟͷදݱ • ΤϯςΟςΟ = ID + υϝΠϯϞσϧ • ܕ΋ύϥϝʔλԽ͞Ε͍ͯΔ •

    υϝΠϯϞσϧʹରͯ͠ڞม • ಉ͡IDܕ͕ͩυϝΠϯϞσϧ͕ҟͳΔ
 ΤϯςΟςΟΛఆٛͰ͖Δ
  11. ίʔυྫ case class EntityKey[ID]( val repr: String ) extends AnyVal

    abstract class Entity[K, +V]( val id: EntityKey[K], val value: V )(implicit ev: V <:< K)
  12. ίʔυྫ case class EntityKey[ID]( val repr: String ) extends AnyVal

    abstract class Entity[K, +V]( val id: EntityKey[K], val value: V )(implicit ev: V <:< K) phantom type
  13. ίʔυྫ case class EntityKey[ID]( val repr: String ) extends AnyVal

    abstract class Entity[K, +V]( val id: EntityKey[K], val value: V )(implicit ev: V <:< K) ஋ܕΛڞมʹ
  14. ίʔυྫ case class EntityKey[ID]( val repr: String ) extends AnyVal

    abstract class Entity[K, +V]( val id: EntityKey[K], val value: V )(implicit ev: V <:< K) ஋ͷܕ͕IDͷܕͷαϒΫϥεͰ͋Δ
 ܕύϥϝʔλ੍໿
  15. ࣮૷ package infra.db trait AccountComponent extends repo.AccountComponent { def accountLoader:

    AccountLoader = AccountDB object AccountDB extends AccountLoader { ... } }
  16. ׬