SlideShare a Scribd company logo
1 of 69
Download to read offline
th e?


Scala in a wild
  enterprise
  Rafael Bagmanov
  ( Grid Dynamics )
In what use cases (types of applications)
    does Scala make the least sense?
"Database front end, CRUD apps.

Most of the boring apps that are built with
Struts and Spring"
                                 David Pollak
                     "Barriers to scala adoption" Infoq.com
OpenGenesis
github.com/griddynamics/OpenGenesis
OpenGenesis
Deployment orchestration tool
● open source - open-genesis.org
● 2 years of development
● > 50 KLOC of scala code
● successfully deployed to production in one
  large american financial institution
● Buzzwords: continuous deployment, cloud,
  chef, devops, aws, openstack
Enterprise characteristics
● Integration with legacy apps and data (lots of
  SOAP and xml)
● sophisticated security policies
● IT department separated from development
  team
● J2EE Containers everywhere
● Risk averse
Typical "lightweight" j2ee stack


      Web layer        Spring MVC


     Service layer     Spring


   Data access layer
                       JPA


         DB
j2ee stack. Scala edition


       Web layer        Spring MVC + scala magic


      Service layer     Spring + scala implicits


    Data access layer
                        JPA Squeryl


          DB
j2ee stack. Scala edition

 WAR

                  Spring MVC
          Web layer



                     Spring
         Service layer



                      Squeryl
       Data access layer




             DB
j2ee stack. Scala edition + scala
                            goodness
 WAR

                  Spring MVC
          Web layer


                                                Akka
                     Spring
                                Workflow distributed
         Service layer                 engine


                      Squeryl
       Data access layer




             DB
Service layer: Spring
Spring with scala
● DI fits almost nicely with scala
Spring with scala
● DI fits almost nicely with scala
  class GenesisRestController {
      @Autowired var genesisService: GenesisService = _
  }


  class GenesisRestController {
      @BeanProperty var genesisService: GenesisService = _
  }


  class GenesisRestController (genesisService: GenesisService) {}
Spring with scala
● DI fits almost nicely with scala
   ○ "Everything is a trait" approach can't be done
Spring with scala
● DI fits almost nicely with scala
   ○ "Everything is a trait" approach can't be done
   ○ Be aware of type inference in @Configuration bean
      trait Service


      class ServiceImpl extends Service


      @Configuration
      class ServiceContext {
          @Bean def service = new ServiceImpl
      }
Spring with scala
● DI fits almost nicely with scala
   ○ "Everything is a trait" approach can't be done
   ○ Be aware of type inference in @Configuration bean
      trait Service


      class ServiceImpl extends Service


      @Configuration
      class ServiceContext {
          @Bean def service: Service = new ServiceImpl
      }
Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.

  springLdapTemplate.authenticate("user", "*", "password", new
  AuthenticationErrorCallback {
       def execute(e: Exception) {log.error(e)}
  })
Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.

  springLdapTemplate.authenticate("user", "*", "password", new
  AuthenticationErrorCallback {
       def execute(e: Exception) {log.error(e)}
  })
Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.

  springLdapTemplate.authenticate("user", "*", "password", new
  AuthenticationErrorCallback {
       def execute(e: Exception) {log.error(e)}
  })


  springLdapTemplate.authenticate("user", "*", "password", log.error(_))
Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.

  springLdapTemplate.authenticate("user", "*", "password", log.error(_))


  implicit def authErrorCallbackWrapper(func:(Exception) => Any) = {
      new AuthenticationErrorCallback {
        def execute(exception: Exception): Unit = func(exception)
      }
  }
Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
● AOP for free (almost)
Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
● AOP for free (almost)
   ○ Be aware of naming in debug info
    def findUsers(projectId: Int) {
        dao.findUsers(projectId)
    }


    def findUsers2(projectId: Int) {
        dao.allUsers().filter(_.projectId == projectId)
    }
Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
● AOP for free (almost)
   ○ Be aware of naming in debug info
    def findUsers(projectId: Int) {     // debugIfo: name "projectId"
        dao.findUsers(projectId)
    }


    def findUsers2(projectId: Int) { // debugInfo: name "projectId$"
        dao.allUsers().filter(_.projectId == projectId)
    }
Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
● AOP for free (almost)
● Spring security just works
Persistence layer: Squeryl
Squeryl
● Lightweight ORM written in scala
Squeryl
● Lightweight ORM written in scala

   class Workflow(override val id: Int) extends KeyedEntity[Int]
Squeryl
● Lightweight ORM written in scala

   class Workflow(override val id: Int) extends KeyedEntity[Int]


   object GS extends Schema {
       val workflows = table[Workflow]
   }
Squeryl
● Lightweight ORM written in scala
   class Workflow(override val id: Int) extends KeyedEntity[Int]


   object GS extends Schema {
       val workflows = table[Workflow]
   }


   def find(workflowId: Int) = from(GS.workflows)(w =>
       where(w.id === workflowId)
        select (w)
        orderBy(w.id desc)
   )
Squeryl
● Lightweight ORM written in scala
  ○ First class support for scala collections, options, etc
Squeryl
● Lightweight ORM written in scala
  ○ First class support for scala collections, options, etc
  ○ Integrates with spring transaction management
     (not out of the box)
Squeryl
● Lightweight ORM written in scala
  ○ First class support for scala collections, options, etc
  ○ Integrates with spring transaction management
     (not out of the box)
     @Transactional(propagation = REQUIRES_NEW)
     def find(workflowId: Int) = from(GS.workflows)(w =>
         where(w.id === workflowId)
          select (w)
          orderBy(w.id desc)
     )
Squeryl
● Lightweight ORM written in scala
   ○   Likes heap in the same proportion as
       Hibernate does
hibernate                                     squeryl
Squeryl
● Lightweight ORM written in scala
  ○   Likes heap in the same proportion as
      Hibernate does
  ○ Lot's of "black magic" in source code
Squeryl
● Lightweight ORM written in scala
● Internal scala DSL for writing queries
   ○ Type safe queries - compile time syntax check
Squeryl
● Lightweight ORM written in scala
● Internal scala DSL for writing queries
   ○ Lot's of "black magic" in source code
Squeryl
● Lightweight ORM written in scala
● Internal scala DSL for writing queries
   ○ Lot's of "black magic" in source code
   ○ Fallback on native sql is not easy
Squeryl
● Lightweight ORM written in scala
● Internal scala DSL for writing queries
   ○ Lot's of "black magic" in source code
   ○ Fallback on native sql is not easy
   ○   Lots of implicits drives IDE crazy and
       increases compilation time
Squeryl
● Lightweight ORM written in scala
● Internal scala DSL for writing queries
   ○ Lot's of "black magic" in source code
   ○ Fallback on native sql is not easy
   ○   Lots of implicits drives IDE crazy and
       increase compilation time
   ○ The approach is somewhat flawed (opinion)
Web layer: Spring MVC
               lift-json
           scala magic
Web layer
● RESTfull web services
  case class User (
       @NotBlank username: String,
       @Email @Size(min = 1, max = 256) email: String,
       password: Option[String]
  )
  @Controller
  @RequestMapping(Array("/rest/users"))
  class UsersController {
      @RequestMapping(method = Array(RequestMethod.POST))
      @ResponseBody
      def create(@RequestBody @Valid request: User): User = userService.create(request)
  }
Web layer
● RESTfull web services
● Easy to make Hypermedia REST with
  implicits
  @Controller
  @RequestMapping(Array("/rest/users"))
  class UsersController {
      import com.griddynamics.genesis.rest.links.Hypermedia._


      @RequestMapping(method = Array(RequestMethod.POST))
      @ResponseBody
      def create(@RequestBody @Valid request: User): Hypermedia[User] = {
       userService.create(request).withLink("/rest/users", LinkType.SELF)
  }
Couple of words about
        AKKA
Ехал Акка через Акка
Смотрит Акка в Акка Акка
 Сунул Акка Акка в Акка
  Акка Акка Акка Акка *



                          * Ode to Akka in russian
Greatest challenge:
Greatest challenge:
      People
Challenges
● Hiring is hard
Challenges
● Hiring is hard
  ○ Scala is a talent attraction
Challenges
● Hiring is hard
  ○ Scala is a talent attraction
  ○ In avg: 0.5 interview per month
Challenges
● Hiring is hard
● Settling team standards and code
  convention
Challenges
● Hiring is hard
● Settling team standards and code
  convention
  ○ Tools are not there yet
Challenges
● Hiring is hard
● Settling team standards and code
  convention
  ○ Tools are not there yet
  ○ Between "OCaml" and "Java" fires
Challenges
● Hiring is hard
● Settling team standards and code
  convention
  ○ Tools are not there yet
  ○ Between "OCaml" and "Java" fires
  ○ "Effective scala" by Twitter and "Scala style guide"
     might help (a bit)
The greatest code-review mystery of
all times
How to deal with scala.Option

 if (option.isDefined) {           option match {
                                     case Some(x) => ..
     ..                              case None => ..



                           ?
 }                                 }




                     option.foreach { .. }
The greatest code-review mystery of
all times
How to deal with scala.Option

 if (option.isDefined) {           option match {
                                     case Some(x) => ..
     ..                              case None => ..



                           ?
 }                                 }




                     option.foreach { .. }
Recruiting java
 developers
aka
5 stages of grief
5 stages of grief
1. Denial
2. Anger
3. Bargaining
4. Depression
5. Acceptance
5 stages of grief
1. Denial
2. Anger
3. Bargaining
4. Depression
5. Acceptance
5 stages of grief
1. Denial
2. Anger
3. Bargaining
4. Depression
5. Acceptance
5 stages of grief
1. Denial
2. Anger
3. Bargaining
4. Depression
5. Acceptance
5 stages of grief
1. Denial
2. Anger
3. Bargaining
4. Depression
5. Acceptance
5 stages of grief
1. Denial
2. Anger
3. Bargaining
4. Depression

5.   Acceptance
Scala in a wild enterprise

More Related Content

What's hot

Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuSalesforce Developers
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...smn-automate
 
JavaOne 2017 - Collections.compare:JDK, Eclipse, Guava, Apache... [CON1754]
JavaOne 2017 - Collections.compare:JDK, Eclipse, Guava, Apache... [CON1754]JavaOne 2017 - Collections.compare:JDK, Eclipse, Guava, Apache... [CON1754]
JavaOne 2017 - Collections.compare:JDK, Eclipse, Guava, Apache... [CON1754]Leonardo De Moura Rocha Lima
 
Building an aws sdk for Perl - Granada Perl Workshop 2014
Building an aws sdk for Perl - Granada Perl Workshop 2014Building an aws sdk for Perl - Granada Perl Workshop 2014
Building an aws sdk for Perl - Granada Perl Workshop 2014Jose Luis Martínez
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaWO Community
 
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介scalaconfjp
 
Type-safe front-end development with Scala
Type-safe front-end development with ScalaType-safe front-end development with Scala
Type-safe front-end development with Scalatakezoe
 
How You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in ProductionHow You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in ProductionBoldRadius Solutions
 
Lightbend Lagom: Microservices Just Right
Lightbend Lagom: Microservices Just RightLightbend Lagom: Microservices Just Right
Lightbend Lagom: Microservices Just Rightmircodotta
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San FranciscoMartin Odersky
 
Containerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS LambdaContainerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS LambdaRyan Cuprak
 
Scal`a`ngular - Scala and Angular
Scal`a`ngular - Scala and AngularScal`a`ngular - Scala and Angular
Scal`a`ngular - Scala and AngularKnoldus Inc.
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaSaleem Ansari
 
Paws - Perl AWS SDK Update - November 2015
Paws - Perl AWS SDK Update - November 2015Paws - Perl AWS SDK Update - November 2015
Paws - Perl AWS SDK Update - November 2015Jose Luis Martínez
 
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一scalaconfjp
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論scalaconfjp
 
Кирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumКирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumAlina Vilk
 
Paws: A Perl AWS SDK - YAPC Europe 2015
Paws: A Perl AWS SDK - YAPC Europe 2015Paws: A Perl AWS SDK - YAPC Europe 2015
Paws: A Perl AWS SDK - YAPC Europe 2015CAPSiDE
 
Concurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayConcurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayYardena Meymann
 

What's hot (20)

Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
 
JavaOne 2017 - Collections.compare:JDK, Eclipse, Guava, Apache... [CON1754]
JavaOne 2017 - Collections.compare:JDK, Eclipse, Guava, Apache... [CON1754]JavaOne 2017 - Collections.compare:JDK, Eclipse, Guava, Apache... [CON1754]
JavaOne 2017 - Collections.compare:JDK, Eclipse, Guava, Apache... [CON1754]
 
Building an aws sdk for Perl - Granada Perl Workshop 2014
Building an aws sdk for Perl - Granada Perl Workshop 2014Building an aws sdk for Perl - Granada Perl Workshop 2014
Building an aws sdk for Perl - Granada Perl Workshop 2014
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
 
Type-safe front-end development with Scala
Type-safe front-end development with ScalaType-safe front-end development with Scala
Type-safe front-end development with Scala
 
How You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in ProductionHow You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in Production
 
Lightbend Lagom: Microservices Just Right
Lightbend Lagom: Microservices Just RightLightbend Lagom: Microservices Just Right
Lightbend Lagom: Microservices Just Right
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
Containerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS LambdaContainerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS Lambda
 
Scal`a`ngular - Scala and Angular
Scal`a`ngular - Scala and AngularScal`a`ngular - Scala and Angular
Scal`a`ngular - Scala and Angular
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Paws - Perl AWS SDK Update - November 2015
Paws - Perl AWS SDK Update - November 2015Paws - Perl AWS SDK Update - November 2015
Paws - Perl AWS SDK Update - November 2015
 
Paws - A Perl AWS SDK
Paws - A Perl AWS SDKPaws - A Perl AWS SDK
Paws - A Perl AWS SDK
 
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論
 
Кирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, CiklumКирилл Безпалый, .NET Developer, Ciklum
Кирилл Безпалый, .NET Developer, Ciklum
 
Paws: A Perl AWS SDK - YAPC Europe 2015
Paws: A Perl AWS SDK - YAPC Europe 2015Paws: A Perl AWS SDK - YAPC Europe 2015
Paws: A Perl AWS SDK - YAPC Europe 2015
 
Concurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayConcurrency in Scala - the Akka way
Concurrency in Scala - the Akka way
 

Viewers also liked

JSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web AppsJSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web AppsGregg Kellogg
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorStéphane Maldini
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftTalentica Software
 
Website to get more pinterest followers
Website to get more pinterest followersWebsite to get more pinterest followers
Website to get more pinterest followersshaun569
 
Op4 outline : review
Op4 outline : reviewOp4 outline : review
Op4 outline : reviewSimha Bode
 
Premios día de andalucía 2013
Premios día de andalucía 2013Premios día de andalucía 2013
Premios día de andalucía 2013adrioper
 
Living culture of bread
Living culture of bread Living culture of bread
Living culture of bread Simha Bode
 
Самосознание
СамосознаниеСамосознание
Самосознаниеlelich6
 
Community booklet
Community bookletCommunity booklet
Community bookletSimha Bode
 
Orientation integrative ecosocial design
Orientation integrative ecosocial designOrientation integrative ecosocial design
Orientation integrative ecosocial designSimha Bode
 
I.S. permaculture handout
I.S. permaculture handoutI.S. permaculture handout
I.S. permaculture handoutSimha Bode
 
Simha’s curriculum for i.s. leadership training
Simha’s curriculum for i.s. leadership trainingSimha’s curriculum for i.s. leadership training
Simha’s curriculum for i.s. leadership trainingSimha Bode
 
Teachers manual to facilitating an earth oven course 1
Teachers manual to facilitating an earth oven course 1Teachers manual to facilitating an earth oven course 1
Teachers manual to facilitating an earth oven course 1Simha Bode
 
Google analytics training bmit 8 09-2016
Google analytics training bmit 8 09-2016Google analytics training bmit 8 09-2016
Google analytics training bmit 8 09-2016Gerard Rathenau
 
Generation now communication
Generation now   communicationGeneration now   communication
Generation now communicationSimha Bode
 

Viewers also liked (20)

JSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web AppsJSON-LD: Linked Data for Web Apps
JSON-LD: Linked Data for Web Apps
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and Reactor
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
 
Website to get more pinterest followers
Website to get more pinterest followersWebsite to get more pinterest followers
Website to get more pinterest followers
 
Op4 outline : review
Op4 outline : reviewOp4 outline : review
Op4 outline : review
 
Premios día de andalucía 2013
Premios día de andalucía 2013Premios día de andalucía 2013
Premios día de andalucía 2013
 
Media
MediaMedia
Media
 
Living culture of bread
Living culture of bread Living culture of bread
Living culture of bread
 
Самосознание
СамосознаниеСамосознание
Самосознание
 
Kommunikation - trends & tendenser 2013
Kommunikation - trends & tendenser 2013Kommunikation - trends & tendenser 2013
Kommunikation - trends & tendenser 2013
 
Oven tools
Oven toolsOven tools
Oven tools
 
Meisser genealogy
Meisser genealogyMeisser genealogy
Meisser genealogy
 
Community booklet
Community bookletCommunity booklet
Community booklet
 
Orientation integrative ecosocial design
Orientation integrative ecosocial designOrientation integrative ecosocial design
Orientation integrative ecosocial design
 
I.S. permaculture handout
I.S. permaculture handoutI.S. permaculture handout
I.S. permaculture handout
 
CLICKON Nedir?
CLICKON Nedir?CLICKON Nedir?
CLICKON Nedir?
 
Simha’s curriculum for i.s. leadership training
Simha’s curriculum for i.s. leadership trainingSimha’s curriculum for i.s. leadership training
Simha’s curriculum for i.s. leadership training
 
Teachers manual to facilitating an earth oven course 1
Teachers manual to facilitating an earth oven course 1Teachers manual to facilitating an earth oven course 1
Teachers manual to facilitating an earth oven course 1
 
Google analytics training bmit 8 09-2016
Google analytics training bmit 8 09-2016Google analytics training bmit 8 09-2016
Google analytics training bmit 8 09-2016
 
Generation now communication
Generation now   communicationGeneration now   communication
Generation now communication
 

Similar to Scala in a wild enterprise

Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»e-Legion
 
Scala Frustrations
Scala FrustrationsScala Frustrations
Scala Frustrationstakezoe
 
Scala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSScala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSAlberto Paro
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Codemotion
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffJAX London
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMarakana Inc.
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scalascalaconfjp
 
Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016takezoe
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistpmanvi
 
Kabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_tech
Kabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_techKabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_tech
Kabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_techKazuhiro Sera
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark Summit
 
Spark Sql for Training
Spark Sql for TrainingSpark Sql for Training
Spark Sql for TrainingBryan Yang
 
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020Thodoris Bais
 
Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkLuciano Mammino
 

Similar to Scala in a wild enterprise (20)

Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»
 
Scala Frustrations
Scala FrustrationsScala Frustrations
Scala Frustrations
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
Scala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSScala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJS
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for Scala
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scala
 
Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologist
 
Devoxx
DevoxxDevoxx
Devoxx
 
Scala active record
Scala active recordScala active record
Scala active record
 
Kabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_tech
Kabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_techKabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_tech
Kabukiza.tech 1 LT - ScalikeJDBC-Async & Skinny Framework #kbkz_tech
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
 
Spark Sql for Training
Spark Sql for TrainingSpark Sql for Training
Spark Sql for Training
 
Play framework
Play frameworkPlay framework
Play framework
 
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and TypescriptMongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020
 
Building a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless frameworkBuilding a serverless company on AWS lambda and Serverless framework
Building a serverless company on AWS lambda and Serverless framework
 

Scala in a wild enterprise

  • 1.
  • 2.
  • 3. th e? Scala in a wild enterprise Rafael Bagmanov ( Grid Dynamics )
  • 4. In what use cases (types of applications) does Scala make the least sense?
  • 5. "Database front end, CRUD apps. Most of the boring apps that are built with Struts and Spring" David Pollak "Barriers to scala adoption" Infoq.com
  • 6.
  • 8. OpenGenesis Deployment orchestration tool ● open source - open-genesis.org ● 2 years of development ● > 50 KLOC of scala code ● successfully deployed to production in one large american financial institution ● Buzzwords: continuous deployment, cloud, chef, devops, aws, openstack
  • 9. Enterprise characteristics ● Integration with legacy apps and data (lots of SOAP and xml) ● sophisticated security policies ● IT department separated from development team ● J2EE Containers everywhere ● Risk averse
  • 10. Typical "lightweight" j2ee stack Web layer Spring MVC Service layer Spring Data access layer JPA DB
  • 11. j2ee stack. Scala edition Web layer Spring MVC + scala magic Service layer Spring + scala implicits Data access layer JPA Squeryl DB
  • 12. j2ee stack. Scala edition WAR Spring MVC Web layer Spring Service layer Squeryl Data access layer DB
  • 13. j2ee stack. Scala edition + scala goodness WAR Spring MVC Web layer Akka Spring Workflow distributed Service layer engine Squeryl Data access layer DB
  • 15. Spring with scala ● DI fits almost nicely with scala
  • 16. Spring with scala ● DI fits almost nicely with scala class GenesisRestController { @Autowired var genesisService: GenesisService = _ } class GenesisRestController { @BeanProperty var genesisService: GenesisService = _ } class GenesisRestController (genesisService: GenesisService) {}
  • 17. Spring with scala ● DI fits almost nicely with scala ○ "Everything is a trait" approach can't be done
  • 18. Spring with scala ● DI fits almost nicely with scala ○ "Everything is a trait" approach can't be done ○ Be aware of type inference in @Configuration bean trait Service class ServiceImpl extends Service @Configuration class ServiceContext { @Bean def service = new ServiceImpl }
  • 19. Spring with scala ● DI fits almost nicely with scala ○ "Everything is a trait" approach can't be done ○ Be aware of type inference in @Configuration bean trait Service class ServiceImpl extends Service @Configuration class ServiceContext { @Bean def service: Service = new ServiceImpl }
  • 20. Spring with scala ● DI fits almost nicely with scala ● Rich spring templates libraries.
  • 21. Spring with scala ● DI fits almost nicely with scala ● Rich spring templates libraries. springLdapTemplate.authenticate("user", "*", "password", new AuthenticationErrorCallback { def execute(e: Exception) {log.error(e)} })
  • 22. Spring with scala ● DI fits almost nicely with scala ● Rich spring templates libraries. springLdapTemplate.authenticate("user", "*", "password", new AuthenticationErrorCallback { def execute(e: Exception) {log.error(e)} })
  • 23. Spring with scala ● DI fits almost nicely with scala ● Rich spring templates libraries. springLdapTemplate.authenticate("user", "*", "password", new AuthenticationErrorCallback { def execute(e: Exception) {log.error(e)} }) springLdapTemplate.authenticate("user", "*", "password", log.error(_))
  • 24. Spring with scala ● DI fits almost nicely with scala ● Rich spring templates libraries. springLdapTemplate.authenticate("user", "*", "password", log.error(_)) implicit def authErrorCallbackWrapper(func:(Exception) => Any) = { new AuthenticationErrorCallback { def execute(exception: Exception): Unit = func(exception) } }
  • 25. Spring with scala ● DI fits almost nicely with scala ● Rich spring templates libraries. ● AOP for free (almost)
  • 26. Spring with scala ● DI fits almost nicely with scala ● Rich spring templates libraries. ● AOP for free (almost) ○ Be aware of naming in debug info def findUsers(projectId: Int) { dao.findUsers(projectId) } def findUsers2(projectId: Int) { dao.allUsers().filter(_.projectId == projectId) }
  • 27. Spring with scala ● DI fits almost nicely with scala ● Rich spring templates libraries. ● AOP for free (almost) ○ Be aware of naming in debug info def findUsers(projectId: Int) { // debugIfo: name "projectId" dao.findUsers(projectId) } def findUsers2(projectId: Int) { // debugInfo: name "projectId$" dao.allUsers().filter(_.projectId == projectId) }
  • 28. Spring with scala ● DI fits almost nicely with scala ● Rich spring templates libraries. ● AOP for free (almost) ● Spring security just works
  • 30. Squeryl ● Lightweight ORM written in scala
  • 31. Squeryl ● Lightweight ORM written in scala class Workflow(override val id: Int) extends KeyedEntity[Int]
  • 32. Squeryl ● Lightweight ORM written in scala class Workflow(override val id: Int) extends KeyedEntity[Int] object GS extends Schema { val workflows = table[Workflow] }
  • 33. Squeryl ● Lightweight ORM written in scala class Workflow(override val id: Int) extends KeyedEntity[Int] object GS extends Schema { val workflows = table[Workflow] } def find(workflowId: Int) = from(GS.workflows)(w => where(w.id === workflowId) select (w) orderBy(w.id desc) )
  • 34. Squeryl ● Lightweight ORM written in scala ○ First class support for scala collections, options, etc
  • 35. Squeryl ● Lightweight ORM written in scala ○ First class support for scala collections, options, etc ○ Integrates with spring transaction management (not out of the box)
  • 36. Squeryl ● Lightweight ORM written in scala ○ First class support for scala collections, options, etc ○ Integrates with spring transaction management (not out of the box) @Transactional(propagation = REQUIRES_NEW) def find(workflowId: Int) = from(GS.workflows)(w => where(w.id === workflowId) select (w) orderBy(w.id desc) )
  • 37. Squeryl ● Lightweight ORM written in scala ○ Likes heap in the same proportion as Hibernate does hibernate squeryl
  • 38. Squeryl ● Lightweight ORM written in scala ○ Likes heap in the same proportion as Hibernate does ○ Lot's of "black magic" in source code
  • 39. Squeryl ● Lightweight ORM written in scala ● Internal scala DSL for writing queries ○ Type safe queries - compile time syntax check
  • 40. Squeryl ● Lightweight ORM written in scala ● Internal scala DSL for writing queries ○ Lot's of "black magic" in source code
  • 41. Squeryl ● Lightweight ORM written in scala ● Internal scala DSL for writing queries ○ Lot's of "black magic" in source code ○ Fallback on native sql is not easy
  • 42. Squeryl ● Lightweight ORM written in scala ● Internal scala DSL for writing queries ○ Lot's of "black magic" in source code ○ Fallback on native sql is not easy ○ Lots of implicits drives IDE crazy and increases compilation time
  • 43. Squeryl ● Lightweight ORM written in scala ● Internal scala DSL for writing queries ○ Lot's of "black magic" in source code ○ Fallback on native sql is not easy ○ Lots of implicits drives IDE crazy and increase compilation time ○ The approach is somewhat flawed (opinion)
  • 44. Web layer: Spring MVC lift-json scala magic
  • 45. Web layer ● RESTfull web services case class User ( @NotBlank username: String, @Email @Size(min = 1, max = 256) email: String, password: Option[String] ) @Controller @RequestMapping(Array("/rest/users")) class UsersController { @RequestMapping(method = Array(RequestMethod.POST)) @ResponseBody def create(@RequestBody @Valid request: User): User = userService.create(request) }
  • 46. Web layer ● RESTfull web services ● Easy to make Hypermedia REST with implicits @Controller @RequestMapping(Array("/rest/users")) class UsersController { import com.griddynamics.genesis.rest.links.Hypermedia._ @RequestMapping(method = Array(RequestMethod.POST)) @ResponseBody def create(@RequestBody @Valid request: User): Hypermedia[User] = { userService.create(request).withLink("/rest/users", LinkType.SELF) }
  • 47. Couple of words about AKKA
  • 48. Ехал Акка через Акка Смотрит Акка в Акка Акка Сунул Акка Акка в Акка Акка Акка Акка Акка * * Ode to Akka in russian
  • 52. Challenges ● Hiring is hard ○ Scala is a talent attraction
  • 53. Challenges ● Hiring is hard ○ Scala is a talent attraction ○ In avg: 0.5 interview per month
  • 54. Challenges ● Hiring is hard ● Settling team standards and code convention
  • 55. Challenges ● Hiring is hard ● Settling team standards and code convention ○ Tools are not there yet
  • 56. Challenges ● Hiring is hard ● Settling team standards and code convention ○ Tools are not there yet ○ Between "OCaml" and "Java" fires
  • 57. Challenges ● Hiring is hard ● Settling team standards and code convention ○ Tools are not there yet ○ Between "OCaml" and "Java" fires ○ "Effective scala" by Twitter and "Scala style guide" might help (a bit)
  • 58. The greatest code-review mystery of all times How to deal with scala.Option if (option.isDefined) { option match { case Some(x) => .. .. case None => .. ? } } option.foreach { .. }
  • 59. The greatest code-review mystery of all times How to deal with scala.Option if (option.isDefined) { option match { case Some(x) => .. .. case None => .. ? } } option.foreach { .. }
  • 61. aka
  • 62. 5 stages of grief
  • 63. 5 stages of grief 1. Denial 2. Anger 3. Bargaining 4. Depression 5. Acceptance
  • 64. 5 stages of grief 1. Denial 2. Anger 3. Bargaining 4. Depression 5. Acceptance
  • 65. 5 stages of grief 1. Denial 2. Anger 3. Bargaining 4. Depression 5. Acceptance
  • 66. 5 stages of grief 1. Denial 2. Anger 3. Bargaining 4. Depression 5. Acceptance
  • 67. 5 stages of grief 1. Denial 2. Anger 3. Bargaining 4. Depression 5. Acceptance
  • 68. 5 stages of grief 1. Denial 2. Anger 3. Bargaining 4. Depression 5. Acceptance