SlideShare a Scribd company logo
1 of 64
Download to read offline
sbt,
history of JSON libraries,
microservices, and
schema evolution
Eugene Yokota (@eed3si9n)

February, 2017
• Scala hobbyist since 2010
• scalaxb (XML data binding)
• treehugger.scala
• sbt-assembly, sbt-buildinfo, etc
• “learning Scalaz” / “herding Cats”
• ScalaMatsuri
• Lightbend/Typesafe since 2014
• tech lead of Reactive Platform team
• current maintainer / tech lead of sbt
who is this guy (@eed3si9n)?
Lightbend Production Suite
big picture: development at scale
• How do you scale a technological organization?
• Goal: Sustainable development
development at scale
• Bezos mandate (written circa 2002 before AWS) https://plus.google.com/
+RipRowan/posts/eVeouesvaVX
microservice is a social stack
1. All teams will henceforth expose their data and functionality through service interfaces.
2. Teams must communicate with each other through these interfaces.
3. There will be no other form of inter-process communication allowed: no direct linking, no direct
reads of another team’s data store, no shared-memory model, no back-doors whatsoever. The only
communication allowed is via service interface calls over the network.
4. It doesn’t matter what technology they use. HTTP, Corba, Pubsub, custom protocols -- doesn't
matter. Bezos doesn't care.
5. All service interfaces, without exception, must be designed from the ground up to be externalizable.
That is to say, the team must plan and design to be able to expose the interface to developers in the
outside world. No exceptions.
6. Anyone who doesn't do this will be fired.
Brief history of
JSON libraries
Eugene Yokota (@eed3si9n)

2016
Brief history of JSON libraries
Dispatch JSON
literaljson
Lift JSON
sjson
Spray JSON
Play JSON
Argonaut
json4s
Circe
Jawn
SLIP-28 JSON
Rapture JSON
sjson-new
2009 2010 2014
2008
Two books
Programming in Scala
import scala.util.parsing.combinator._
class JSON extends JavaTokenParsers {
def value : Parser[Any] = obj | arr |
stringLiteral |
floatingPointNumber |
"null" | "true" | "false"
def obj : Parser[Any] = "{"~repsep(member, ",")~"}"
def arr : Parser[Any] = "["~repsep(value, ",")~"]"
def member: Parser[Any] = stringLiteral~":"~value
}
https://www.artima.com/pins1ed/combinator-parsing.html#31.4
• Chapter 5. Writing a library: working with JSON data
Real World Haskell
data JValue = JString String
| JNumber Double
| JBool Bool
| JNull
| JObject [(String, JValue)]
| JArray [JValue]
deriving (Eq, Ord, Show)
2009
• https://github.com/dispatch/dispatch/commit/
41edb939baa5c6edb4378c1bd8e1d2f10f3350f2
• Contributed by Jorge Ortiz
• Parsing using parser combinator
• Values stored in AST, JsValue
Dispatch JSON
• https://github.com/jonifreeman/literaljson
• Authored by Joni Freeman
• Custom parser
• Values stored in AST, JValue
• On August 11, 2009, Joni contributed literaljson to
Lift, and became Lift-JSON
jonifreeman/literaljson
2010
• https://github.com/debasishg/sjson
• Authored by Debasish Ghosh
• sjson: Now offers Type Class based JSON
Serialization in Scala
• Uses Dispatch JSON for AST
sjson
Typeclass
• Allows adding capability to a class after the fact in a
typesafe manner.
Typeclass
trait Eq[A] {
  def equals(x: A, y: A): Boolean
}
• Eq typeclass can enable === operator to compare
only the supported types, and prevent compilation
of "1" === 1
• Scala Implicits : Type Classes Here I Come
JsonFormat
trait CanRead[A] {
  def reads(json: JsValue): A
}
trait CanWrite[A] {
  def writes(a: A): JsValue
}
trait JsonFormat[A] extends CanRead[A]
with CanWrite[A]
implicit val intFormat: JsonFormat[Int] = ...
JsonFormat
• JsonFormat typeclass allows conversion to and
from an arbitrary type to a JSON AST.
2011
• https://github.com/spray/spray-json
• Authored by Mathias Dönitz
• Original parser
• Ported AST from Dispatch JSON and type classes
from sjson
spray-json
• https://github.com/playframework/playframework/commit/
63448578b15dcc7bf4806878c7b3aa4c74193af6
• Started out as port of Dispatch JSON and sjson typeclasses, but quickly
added its own implementations.
Play JSON
2012
• http://argonaut.io/
• Purely functional JSON library
• Authored by Mark Hibberd, Tony Morris, Sean Parsons
• Uses Scalaz or Cats
• Very feature rich (Lenses, Cursor, History Cursor)
Argonaut
2013
• https://github.com/json4s/json4s
• Fork of Lift-json. JSON library that is not strongly tied to a web
framework.
json4s
2014
• https://github.com/non/jawn
• Authored by Erik Osheim (@d6)
• Backend-independent JSON parser
Jawn
• http://rapture.io/mod/json
• Authored by Jon Pretty
• Backend-independent JSON library
Rapture JSON
2015
• https://github.com/travisbrown/circe
• Authored by Travis Brown
• Port of Argonaut
Circe
2016
• https://github.com/mdedetrich/scala-json-ast
• Authored by Matthew de Detrich
• Aiming to be the common JSON AST
Scala JSON AST (SLIP-28)
• https://github.com/eed3si9n/sjson-new
• Backend-independent typeclass based JSON codec
• No macros
sjson-new
Brief history of JSON libraries
Dispatch JSON
literaljson
Lift JSON
sjson
Spray JSON
Play JSON
Argonaut
json4s
Circe
Jawn
SLIP-28 JSON
Rapture JSON
sjson-new
2009 2010 2014
Contract-first approach
Eugene Yokota (@eed3si9n)

2016
• “Serialization” tends to start from a programming language construct, and it
generates String or byte array.
• Data binding starts with a contract or a schema of the wire format, and generates
the binding in a programming language.
• XML Schema / WSDL
• Google Protocol Buffer
• Apache Thrift
• Apache Avro
• Facebook GraphQL
Serialization vs Data binding
• sealed traits
• case classes
Representing data in Scala
• sealed traits
• case classes
Representing data in Scala
Cannot evolve in a binary compatible way.
Representing data in Scala
class Greeting(name: String) {
  def copy(name: String = name): Greeting = ???
  def unapply(v: Greeting): Option[String] = ???
}
class Greeting(name: String, x: Int) {
  def copy(name: String = name,
x: Int = x): Greeting = ???
  def unapply(v: Greeting): Option[(String, Int)] =
???
}
• sealed traits
• case classes
• Cannot evolve in a binary compatible way.
• But generating equals, hash, and toString is generally useful.
Representing data in Scala
Contraband
• http://www.scala-sbt.org/contraband/
• Contraband is a description language for your datatypes and APIs, currently
targeting Java and Scala.
• Based on GraphQL schema.
Contraband
Record types
package com.example
@target(Scala)
## Character represents the characters in Star Wars.
type Character {
name: String!
appearsIn: [com.example.Episode]!
}
@since annotation
package com.example
@target(Scala)
type Greeting {
value: String!
x: Int @since("0.2.0")
}
Enumeration types
package com.example
@target(Scala)
## Star Wars trilogy.
enum Episode {
NewHope
Empire
Jedi
}
Interfaces
package com.example
@target(Scala)
## Character represents the characters in Star Wars.
interface Character {
name: String!
appearsIn: [com.example.Episode]!
friends: lazy [com.example.Character]
}
Record type example
package com.example
@target(Scala)
type Person {
name: String!
age: Int
}
Record type example
// DO NOT EDIT MANUALLY
package com.example
final class Person private (
  val name: String,
  val age: Option[Int]) extends Serializable {
  override def equals(o: Any): Boolean = o match {
    case x: Person => (this.name == x.name) && (this.age ==
x.age)
    case _ => false
  }
  override def hashCode: Int = {
    37 * (37 * (17 + name.##) + age.##)
  }
  override def toString: String = {
Record type example
  override def toString: String = {
    "Person(" + name + ", " + age + ")"
  }
  protected[this] def copy(name: String = name,
age: Option[Int] = age): Person = {
    new Person(name, age)
  }
  def withName(name: String): Person = {
    copy(name = name)
  }
  def withAge(age: Option[Int]): Person = {
    copy(age = age)
  }
  def withAge(age: Int): Person = {
Record type example
object Person {
  def apply(name: String, age: Option[Int]): Person =
new Person(name, age)
  def apply(name: String, age: Int): Person =
new Person(name, Option(age))
}
Record type example
> val x = Person("Alice", 20)
> x.withAge(21)
Contraband can derive sjson-new codecs
JSON codec generation
package com.example
@target(Scala)
type Person {
name: String!
age: Int
}
JSON codec generation
package generated
import _root_.sjsonnew.{ deserializationError,
serializationError, Builder, JsonFormat, Unbuilder }
trait PersonFormats { self: sjsonnew.BasicJsonProtocol =>
  implicit lazy val personFormat: JsonFormat[_root_.Person] =
JsonFormat[_root_.Person] {
    override def read[J](jsOpt: Option[J], unbuilder:
Unbuilder[J]): _root_.Person = {
      jsOpt match {
        case Some(js) =>
          unbuilder.beginObject(js)
          val name = unbuilder.readField[String]("name")
          val age = unbuilder.readField[Option[Int]]("age")
          unbuilder.endObject()
          _root_.Person(name)
JSON codec generation
scala> import sjsonnew.support.scalajson.unsafe.{ Converter,
CompactPrinter, Parser }
scala> import com.example.codec.CustomJsonProtocol._
scala> import com.example.Person
scala> val p = Person("Bob", 20)
p: com.example.Person = Person(Bob, 20)
scala> val j = Converter.toJsonUnsafe(p)
j: scala.json.ast.unsafe.JValue =
JObject([Lscala.json.ast.unsafe.JField;@6731ad72)
scala> val s = CompactPrinter(j)
s: String = {"name":"Bob","age":20}
scala> val x = Parser.parseUnsafe(s)
JSON codec generation
scala> val s = CompactPrinter(j)
s: String = {"name":"Bob","age":20}
scala> val x = Parser.parseUnsafe(s)
x: scala.json.ast.unsafe.JValue =
JObject([Lscala.json.ast.unsafe.JField;@7331f7f8)
scala> val q = Converter.fromJsonUnsafe[Person](x)
q: com.example.Person = Person(Bob, 20)
scala> assert(p == q)
• http://www.scala-sbt.org/contraband/
• Contraband is a description language for your datatypes and APIs, currently
targeting Java and Scala.
• Low-tech metaprogramming (code generation)
• Binary compatible evolution of pseudo case class.
• Auto derivation of backend-independent JSON codec.
Contraband
• An opportunity for datatype-generic programming.
• For example, one backend is Int
Contraband
• An opportunity for datatype-generic programming.
• For example, one backend is Int (Murmurhash support)
• Builder API is used to build one-way hash.
Contraband
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)

More Related Content

What's hot

Odnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureOdnoklassniki.ru Architecture
Odnoklassniki.ru Architecture
Dmitry Buzdin
 
Ruby - a tester's best friend
Ruby - a tester's best friendRuby - a tester's best friend
Ruby - a tester's best friend
Peter Lind
 

What's hot (20)

FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript Debugging
 
Microservices in Scala: Play Framework
Microservices in Scala: Play FrameworkMicroservices in Scala: Play Framework
Microservices in Scala: Play Framework
 
Databases which, why and usage tips
Databases which, why and usage tipsDatabases which, why and usage tips
Databases which, why and usage tips
 
Perl6 meets JVM
Perl6 meets JVMPerl6 meets JVM
Perl6 meets JVM
 
Scala io2013 : Our journey from UML/MDD to Scala macros
Scala io2013 : Our journey from UML/MDD to Scala macrosScala io2013 : Our journey from UML/MDD to Scala macros
Scala io2013 : Our journey from UML/MDD to Scala macros
 
Apache Camel in the belly of the Docker whale
Apache Camel in the belly of the Docker whaleApache Camel in the belly of the Docker whale
Apache Camel in the belly of the Docker whale
 
JCR - Java Content Repositories
JCR - Java Content RepositoriesJCR - Java Content Repositories
JCR - Java Content Repositories
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Java, Ruby & Rails
Java, Ruby & RailsJava, Ruby & Rails
Java, Ruby & Rails
 
Odnoklassniki.ru Architecture
Odnoklassniki.ru ArchitectureOdnoklassniki.ru Architecture
Odnoklassniki.ru Architecture
 
Railsチュートリアルの歩き方 (第3版)
Railsチュートリアルの歩き方 (第3版)Railsチュートリアルの歩き方 (第3版)
Railsチュートリアルの歩き方 (第3版)
 
Spring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trendsSpring framework 3.2 > 4.0 — themes and trends
Spring framework 3.2 > 4.0 — themes and trends
 
Introduction to CQ5
Introduction to CQ5Introduction to CQ5
Introduction to CQ5
 
Ruby - a tester's best friend
Ruby - a tester's best friendRuby - a tester's best friend
Ruby - a tester's best friend
 
Vert.x – The problem of real-time data binding
Vert.x – The problem of real-time data bindingVert.x – The problem of real-time data binding
Vert.x – The problem of real-time data binding
 
Introduction to Node.js Platform
Introduction to Node.js PlatformIntroduction to Node.js Platform
Introduction to Node.js Platform
 
Ruby on rails toolbox
Ruby on rails toolboxRuby on rails toolbox
Ruby on rails toolbox
 
Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introduction
 
Ansible
AnsibleAnsible
Ansible
 
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Java 8: Nashorn & avatar.js di Enrico Risa al JUG RomaJava 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
 

Viewers also liked

冬のLock free祭り safe
冬のLock free祭り safe冬のLock free祭り safe
冬のLock free祭り safe
Kumazaki Hiroki
 

Viewers also liked (20)

The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
The state of sbt 0.13, sbt server, and sbt 1.0 (ScalaMatsuri ver)
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
DDD patterns that were not in the book
DDD patterns that were not in the bookDDD patterns that were not in the book
DDD patterns that were not in the book
 
データベース設計徹底指南
データベース設計徹底指南データベース設計徹底指南
データベース設計徹底指南
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQLHTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
HTTP, JSON, JavaScript, Map&Reduce built-in to MySQL
 
Json
JsonJson
Json
 
Taking the friction out of microservice frameworks with Lagom
Taking the friction out of microservice frameworks with LagomTaking the friction out of microservice frameworks with Lagom
Taking the friction out of microservice frameworks with Lagom
 
JSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked DataJSON-LD: JSON for Linked Data
JSON-LD: JSON for Linked Data
 
[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボ
[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボ[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボ
[Ecの会社でaiのラボを作りました]ネクストエンジンaiラボ
 
冬のLock free祭り safe
冬のLock free祭り safe冬のLock free祭り safe
冬のLock free祭り safe
 
1.3.18 Организация ввода и распределения электроэнергии до 1 кВ
1.3.18 Организация ввода и распределения электроэнергии до 1 кВ1.3.18 Организация ввода и распределения электроэнергии до 1 кВ
1.3.18 Организация ввода и распределения электроэнергии до 1 кВ
 
2016 in review
2016 in review2016 in review
2016 in review
 
Los 7 Principios del Cerebro
Los 7 Principios del CerebroLos 7 Principios del Cerebro
Los 7 Principios del Cerebro
 
Microservice.net by sergey seletsky
Microservice.net by sergey seletskyMicroservice.net by sergey seletsky
Microservice.net by sergey seletsky
 
10 RAZONES PARA SALIR CON UN JUGADOR DE GOLF
10 RAZONES PARA SALIR CON UN JUGADOR DE GOLF10 RAZONES PARA SALIR CON UN JUGADOR DE GOLF
10 RAZONES PARA SALIR CON UN JUGADOR DE GOLF
 
Sacred Riots
Sacred RiotsSacred Riots
Sacred Riots
 
BARRERAS
BARRERAS BARRERAS
BARRERAS
 
Company presentation ppt
Company presentation pptCompany presentation ppt
Company presentation ppt
 
Mercados verdes en colombia
Mercados verdes en colombiaMercados verdes en colombia
Mercados verdes en colombia
 

Similar to sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)

Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
jeffz
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
json.ppt download for free for college project
json.ppt download for free for college projectjson.ppt download for free for college project
json.ppt download for free for college project
AmitSharma397241
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
 
楽々Scalaプログラミング
楽々Scalaプログラミング楽々Scalaプログラミング
楽々Scalaプログラミング
Tomoharu ASAMI
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02
Ramamohan Chokkam
 

Similar to sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver) (20)

Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Json the-x-in-ajax1588
Json the-x-in-ajax1588Json the-x-in-ajax1588
Json the-x-in-ajax1588
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Scala Introduction
Scala IntroductionScala Introduction
Scala Introduction
 
json.ppt download for free for college project
json.ppt download for free for college projectjson.ppt download for free for college project
json.ppt download for free for college project
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015The Future of Node - @rvagg - NodeConf Christchurch 2015
The Future of Node - @rvagg - NodeConf Christchurch 2015
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
楽々Scalaプログラミング
楽々Scalaプログラミング楽々Scalaプログラミング
楽々Scalaプログラミング
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Json - ideal for data interchange
Json - ideal for data interchangeJson - ideal for data interchange
Json - ideal for data interchange
 
Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 

More from Eugene Yokota

More from Eugene Yokota (10)

Equality in Scala (ScalaMatsuri 2020)
Equality in Scala (ScalaMatsuri 2020)Equality in Scala (ScalaMatsuri 2020)
Equality in Scala (ScalaMatsuri 2020)
 
sbt: core concepts and updates (Scala Love 2020)
sbt: core concepts and updates (Scala Love 2020)sbt: core concepts and updates (Scala Love 2020)
sbt: core concepts and updates (Scala Love 2020)
 
Analysis of Zinc (nescala 2020)
Analysis of Zinc (nescala 2020)Analysis of Zinc (nescala 2020)
Analysis of Zinc (nescala 2020)
 
Analysis of Zinc (ScalaSphere 2019)
Analysis of Zinc (ScalaSphere 2019)Analysis of Zinc (ScalaSphere 2019)
Analysis of Zinc (ScalaSphere 2019)
 
sbt core concepts (ScalaMatsuri 2019)
sbt core concepts (ScalaMatsuri 2019)sbt core concepts (ScalaMatsuri 2019)
sbt core concepts (ScalaMatsuri 2019)
 
pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)
 
sbt 1
sbt 1sbt 1
sbt 1
 
sbt server (LSP discussion, 2018 Jan)
sbt server (LSP discussion, 2018 Jan)sbt server (LSP discussion, 2018 Jan)
sbt server (LSP discussion, 2018 Jan)
 
Thinking in Cats
Thinking in CatsThinking in Cats
Thinking in Cats
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)

  • 1. sbt, history of JSON libraries, microservices, and schema evolution Eugene Yokota (@eed3si9n)
 February, 2017
  • 2. • Scala hobbyist since 2010 • scalaxb (XML data binding) • treehugger.scala • sbt-assembly, sbt-buildinfo, etc • “learning Scalaz” / “herding Cats” • ScalaMatsuri • Lightbend/Typesafe since 2014 • tech lead of Reactive Platform team • current maintainer / tech lead of sbt who is this guy (@eed3si9n)?
  • 4.
  • 6. • How do you scale a technological organization? • Goal: Sustainable development development at scale
  • 7. • Bezos mandate (written circa 2002 before AWS) https://plus.google.com/ +RipRowan/posts/eVeouesvaVX microservice is a social stack 1. All teams will henceforth expose their data and functionality through service interfaces. 2. Teams must communicate with each other through these interfaces. 3. There will be no other form of inter-process communication allowed: no direct linking, no direct reads of another team’s data store, no shared-memory model, no back-doors whatsoever. The only communication allowed is via service interface calls over the network. 4. It doesn’t matter what technology they use. HTTP, Corba, Pubsub, custom protocols -- doesn't matter. Bezos doesn't care. 5. All service interfaces, without exception, must be designed from the ground up to be externalizable. That is to say, the team must plan and design to be able to expose the interface to developers in the outside world. No exceptions. 6. Anyone who doesn't do this will be fired.
  • 8. Brief history of JSON libraries Eugene Yokota (@eed3si9n)
 2016
  • 9. Brief history of JSON libraries Dispatch JSON literaljson Lift JSON sjson Spray JSON Play JSON Argonaut json4s Circe Jawn SLIP-28 JSON Rapture JSON sjson-new 2009 2010 2014
  • 10. 2008
  • 12. Programming in Scala import scala.util.parsing.combinator._ class JSON extends JavaTokenParsers { def value : Parser[Any] = obj | arr | stringLiteral | floatingPointNumber | "null" | "true" | "false" def obj : Parser[Any] = "{"~repsep(member, ",")~"}" def arr : Parser[Any] = "["~repsep(value, ",")~"]" def member: Parser[Any] = stringLiteral~":"~value } https://www.artima.com/pins1ed/combinator-parsing.html#31.4
  • 13. • Chapter 5. Writing a library: working with JSON data Real World Haskell data JValue = JString String | JNumber Double | JBool Bool | JNull | JObject [(String, JValue)] | JArray [JValue] deriving (Eq, Ord, Show)
  • 14. 2009
  • 15. • https://github.com/dispatch/dispatch/commit/ 41edb939baa5c6edb4378c1bd8e1d2f10f3350f2 • Contributed by Jorge Ortiz • Parsing using parser combinator • Values stored in AST, JsValue Dispatch JSON
  • 16. • https://github.com/jonifreeman/literaljson • Authored by Joni Freeman • Custom parser • Values stored in AST, JValue • On August 11, 2009, Joni contributed literaljson to Lift, and became Lift-JSON jonifreeman/literaljson
  • 17. 2010
  • 18. • https://github.com/debasishg/sjson • Authored by Debasish Ghosh • sjson: Now offers Type Class based JSON Serialization in Scala • Uses Dispatch JSON for AST sjson
  • 20. • Allows adding capability to a class after the fact in a typesafe manner. Typeclass trait Eq[A] {   def equals(x: A, y: A): Boolean } • Eq typeclass can enable === operator to compare only the supported types, and prevent compilation of "1" === 1 • Scala Implicits : Type Classes Here I Come
  • 21. JsonFormat trait CanRead[A] {   def reads(json: JsValue): A } trait CanWrite[A] {   def writes(a: A): JsValue } trait JsonFormat[A] extends CanRead[A] with CanWrite[A] implicit val intFormat: JsonFormat[Int] = ...
  • 22. JsonFormat • JsonFormat typeclass allows conversion to and from an arbitrary type to a JSON AST.
  • 23. 2011
  • 24. • https://github.com/spray/spray-json • Authored by Mathias Dönitz • Original parser • Ported AST from Dispatch JSON and type classes from sjson spray-json
  • 25. • https://github.com/playframework/playframework/commit/ 63448578b15dcc7bf4806878c7b3aa4c74193af6 • Started out as port of Dispatch JSON and sjson typeclasses, but quickly added its own implementations. Play JSON
  • 26. 2012
  • 27. • http://argonaut.io/ • Purely functional JSON library • Authored by Mark Hibberd, Tony Morris, Sean Parsons • Uses Scalaz or Cats • Very feature rich (Lenses, Cursor, History Cursor) Argonaut
  • 28. 2013
  • 29. • https://github.com/json4s/json4s • Fork of Lift-json. JSON library that is not strongly tied to a web framework. json4s
  • 30. 2014
  • 31. • https://github.com/non/jawn • Authored by Erik Osheim (@d6) • Backend-independent JSON parser Jawn
  • 32. • http://rapture.io/mod/json • Authored by Jon Pretty • Backend-independent JSON library Rapture JSON
  • 33. 2015
  • 34. • https://github.com/travisbrown/circe • Authored by Travis Brown • Port of Argonaut Circe
  • 35. 2016
  • 36. • https://github.com/mdedetrich/scala-json-ast • Authored by Matthew de Detrich • Aiming to be the common JSON AST Scala JSON AST (SLIP-28)
  • 37. • https://github.com/eed3si9n/sjson-new • Backend-independent typeclass based JSON codec • No macros sjson-new
  • 38. Brief history of JSON libraries Dispatch JSON literaljson Lift JSON sjson Spray JSON Play JSON Argonaut json4s Circe Jawn SLIP-28 JSON Rapture JSON sjson-new 2009 2010 2014
  • 40. • “Serialization” tends to start from a programming language construct, and it generates String or byte array. • Data binding starts with a contract or a schema of the wire format, and generates the binding in a programming language. • XML Schema / WSDL • Google Protocol Buffer • Apache Thrift • Apache Avro • Facebook GraphQL Serialization vs Data binding
  • 41. • sealed traits • case classes Representing data in Scala
  • 42. • sealed traits • case classes Representing data in Scala Cannot evolve in a binary compatible way.
  • 43. Representing data in Scala class Greeting(name: String) {   def copy(name: String = name): Greeting = ???   def unapply(v: Greeting): Option[String] = ??? } class Greeting(name: String, x: Int) {   def copy(name: String = name, x: Int = x): Greeting = ???   def unapply(v: Greeting): Option[(String, Int)] = ??? }
  • 44. • sealed traits • case classes • Cannot evolve in a binary compatible way. • But generating equals, hash, and toString is generally useful. Representing data in Scala
  • 46. • http://www.scala-sbt.org/contraband/ • Contraband is a description language for your datatypes and APIs, currently targeting Java and Scala. • Based on GraphQL schema. Contraband
  • 47. Record types package com.example @target(Scala) ## Character represents the characters in Star Wars. type Character { name: String! appearsIn: [com.example.Episode]! }
  • 48. @since annotation package com.example @target(Scala) type Greeting { value: String! x: Int @since("0.2.0") }
  • 49. Enumeration types package com.example @target(Scala) ## Star Wars trilogy. enum Episode { NewHope Empire Jedi }
  • 50. Interfaces package com.example @target(Scala) ## Character represents the characters in Star Wars. interface Character { name: String! appearsIn: [com.example.Episode]! friends: lazy [com.example.Character] }
  • 51. Record type example package com.example @target(Scala) type Person { name: String! age: Int }
  • 52. Record type example // DO NOT EDIT MANUALLY package com.example final class Person private (   val name: String,   val age: Option[Int]) extends Serializable {   override def equals(o: Any): Boolean = o match {     case x: Person => (this.name == x.name) && (this.age == x.age)     case _ => false   }   override def hashCode: Int = {     37 * (37 * (17 + name.##) + age.##)   }   override def toString: String = {
  • 53. Record type example   override def toString: String = {     "Person(" + name + ", " + age + ")"   }   protected[this] def copy(name: String = name, age: Option[Int] = age): Person = {     new Person(name, age)   }   def withName(name: String): Person = {     copy(name = name)   }   def withAge(age: Option[Int]): Person = {     copy(age = age)   }   def withAge(age: Int): Person = {
  • 54. Record type example object Person {   def apply(name: String, age: Option[Int]): Person = new Person(name, age)   def apply(name: String, age: Int): Person = new Person(name, Option(age)) }
  • 55. Record type example > val x = Person("Alice", 20) > x.withAge(21)
  • 56. Contraband can derive sjson-new codecs
  • 57. JSON codec generation package com.example @target(Scala) type Person { name: String! age: Int }
  • 58. JSON codec generation package generated import _root_.sjsonnew.{ deserializationError, serializationError, Builder, JsonFormat, Unbuilder } trait PersonFormats { self: sjsonnew.BasicJsonProtocol =>   implicit lazy val personFormat: JsonFormat[_root_.Person] = JsonFormat[_root_.Person] {     override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): _root_.Person = {       jsOpt match {         case Some(js) =>           unbuilder.beginObject(js)           val name = unbuilder.readField[String]("name")           val age = unbuilder.readField[Option[Int]]("age")           unbuilder.endObject()           _root_.Person(name)
  • 59. JSON codec generation scala> import sjsonnew.support.scalajson.unsafe.{ Converter, CompactPrinter, Parser } scala> import com.example.codec.CustomJsonProtocol._ scala> import com.example.Person scala> val p = Person("Bob", 20) p: com.example.Person = Person(Bob, 20) scala> val j = Converter.toJsonUnsafe(p) j: scala.json.ast.unsafe.JValue = JObject([Lscala.json.ast.unsafe.JField;@6731ad72) scala> val s = CompactPrinter(j) s: String = {"name":"Bob","age":20} scala> val x = Parser.parseUnsafe(s)
  • 60. JSON codec generation scala> val s = CompactPrinter(j) s: String = {"name":"Bob","age":20} scala> val x = Parser.parseUnsafe(s) x: scala.json.ast.unsafe.JValue = JObject([Lscala.json.ast.unsafe.JField;@7331f7f8) scala> val q = Converter.fromJsonUnsafe[Person](x) q: com.example.Person = Person(Bob, 20) scala> assert(p == q)
  • 61. • http://www.scala-sbt.org/contraband/ • Contraband is a description language for your datatypes and APIs, currently targeting Java and Scala. • Low-tech metaprogramming (code generation) • Binary compatible evolution of pseudo case class. • Auto derivation of backend-independent JSON codec. Contraband
  • 62. • An opportunity for datatype-generic programming. • For example, one backend is Int Contraband
  • 63. • An opportunity for datatype-generic programming. • For example, one backend is Int (Murmurhash support) • Builder API is used to build one-way hash. Contraband