SlideShare a Scribd company logo
1 of 52
Download to read offline
Use of Scala in dwango

niconico Android API


  後藤 哲志 (Satoshi Goto)
    DWANGO Co.,Ltd.
Attention

We talk about API server
using Scala and Play

niconico Android (app) is
written by Java
Contents


Self-introduction (自己紹介)

Project introduction (プロジェクト紹介)

Scala pros/cons (いいところ 悪いところ)
Satoshi Goto


ニコニコ事業統括本部 プラットフォーム
事業本部 第一企画開発部 第4セクション

ニコニコAndroid サーバチーム所属

id:mtgto (twitter, GitHub, Qiita)
Works at
niconico
niconico is 6-year-old
  PC (Windows, Mac, Linux, etc.)

  Feature phone (docomo, au, softbank,
  willcom)

  iPhone

  PS Vita

  TV

  WiiU

  Windows 8
niconico is 6-year-old
  PC (Windows, Mac, Linux, etc.)

  Feature phone (docomo, au, softbank,
  willcom)

  iPhone

  PS Vita

  TV

  WiiU            &Android!
  Windows 8
Project History
2012/2 Project launched

2012/8 au STB App released

2012/11 Android App released



Deployed 22 times

2.5 million requests / day
Our team

Planner: 1

Android developers: 5

API server developers: 6

Infra-engineers: 2
API server
     members
@tomoyoshi_ogura

@kozo1215

@fedista

@mitikage

@kimwoonsung

@mtgto
API server
     members
Old member
@tomoyoshi_ogura

@kozo1215

@fedista I♥

        Scala
@mitikage

@kimwoonsung

@mtgto
Internal
          API
Video
 API
            niconico
            Android
               API
Live         Scala 2.9.1
API
              Play 2.0
niconico Android API is
dwango s first service
written in Scala
74 API

Video (動画)

 Ranking, Search, Tags, MyList

Live (生放送)

 Ranking, Search, Tags

Channel, Community, News
Niconico Android
        is
     PROXY
        ?
Niconico Android
        is !
      N O
     PROXY
        ?
Re-defined typed model




 Anticorruption LAYER (腐敗防止層)

  lingo                          ambiguous
(社内用語)           various
                                  definition
              characteristics
                                (曖昧な定義)
   nullable
Why Scala ?

Increasing interests in Scala

  Scala workshop in dwango

Strong compiler check

Experimental project
Our products


Core library

API server

Management server
Core
based on DDD concept

Scala (& Java enumeration)

sbt + IntelliJ IDEA (sbt-idea)

jedis (redis client) for caching

  Using Java serialization

Specs 2 + Mockito
Open API

based on Core Library

Play 2.0.2 (JSON only)

Redis-based sessions (using jedis)

CSRF-free customized Action (Play)

Daemonized (Apache Daemon)
Management


based on Core Library

Play 2.0.2 (Internal web system)

Statistics and Operations

Daemonized (Apache Daemon)
Project scale

           # of files   # of tests   LOC


 CORE        665          976       52k


OPEN API      75          530       21k


manage        32          173       2k
TEST (Core)
            Almost 1000


TODO: Jenkinsのスクリーンショット



      TODO:テスト件数
         80% Coverage
Pros



Option

match & sealed trait
Option
∼Say goodbye to NullPointerException∼
Null check is boring



              Java


              Scala
match
     &
sealed trait
match
match
match




  Use scalac option
  -Xfatal-warnings
Cons


case class limitation

Jenkins server swap out

Play framework

  CSRF / Akka
Case Class
Case class useful!

 equals

 hashCode

 toString

 etc.
             defined
          automatically!
Tuple22
limitation!
Case classes
represent XML API
Case classes
represent XML API



       32 Elements
Case classes
represent XML API
Case classes
represent XML API


        96
     Elements
Jenkins
Swap out
Jenkins swap out

Scalac obtains over 1GB memory
Jenkins swap out

Scalac obtains over 1GB memory



 Restricted the number of

 simultaneous jenkins jobs...

 (4 -> 2 -> 1)
Play / CSRF
CSRF self check

 Implements Customized Action to
 check CSRF like below:


• if Method == POST ¦ PUT ¦ DELETE
 • if request.body( token ) != token
   • BadRequest
Play / Akka
Request Overflowed

 In production
 environment, Play
 causes many
 exceptions
Request Overflowed

    In production
   ERROR play Cannot invoke the
   action, eventually got an error:
    environment, Play
Thrown(akka.pattern.AskTimeoutExc
    causes many out)
         eption: Timed
    exceptions
Few documentation
    for Akka...

http://www.playframework.com/documentation/2.0.4/
                    AkkaCore
Increase number of threads
      from 24 to 100
Extends timeouts from 5 to 10
           seconds



Almost errors aren’t occurred
Conclusion


We rarely faced
critical troubles
while we are using
Scala in our project
Thank you for listening!
https://play.google.com/
   store/apps/details?
 id=jp.nicovideo.android

More Related Content

Similar to ドワンゴでのScala活用事例「ニコニコandroid」

Real World Android Akka
Real World Android AkkaReal World Android Akka
Real World Android AkkaTaisuke Oe
 
Introduction and hacking OpenStack, Pycon India
Introduction and hacking OpenStack,  Pycon IndiaIntroduction and hacking OpenStack,  Pycon India
Introduction and hacking OpenStack, Pycon IndiaAtul Jha
 
Java compilation
Java compilationJava compilation
Java compilationMike Kucera
 
What’s Slowing Down Your Kafka Pipeline? With Ruizhe Cheng and Pete Stevenson...
What’s Slowing Down Your Kafka Pipeline? With Ruizhe Cheng and Pete Stevenson...What’s Slowing Down Your Kafka Pipeline? With Ruizhe Cheng and Pete Stevenson...
What’s Slowing Down Your Kafka Pipeline? With Ruizhe Cheng and Pete Stevenson...HostedbyConfluent
 
Eric Lafortune - The Jack and Jill build system
Eric Lafortune - The Jack and Jill build systemEric Lafortune - The Jack and Jill build system
Eric Lafortune - The Jack and Jill build systemGuardSquare
 
Eric Lafortune - The Jack and Jill build system
Eric Lafortune - The Jack and Jill build systemEric Lafortune - The Jack and Jill build system
Eric Lafortune - The Jack and Jill build systemGuardSquare
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Saeed Zarinfam
 
Code Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCoCode Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCoEvgeny Mandrikov
 
0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlab0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlabNational Cheng Kung University
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaWO Community
 
Spinnaker 파트 1
Spinnaker 파트 1Spinnaker 파트 1
Spinnaker 파트 1Steven Shim
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)JiandSon
 
Efficient mobile automation
Efficient mobile automationEfficient mobile automation
Efficient mobile automationVitaly Tatarinov
 
Building a modern SaaS in 2020
Building a modern SaaS in 2020Building a modern SaaS in 2020
Building a modern SaaS in 2020Nikolay Stoitsev
 
Java 40 versions_sgp
Java 40 versions_sgpJava 40 versions_sgp
Java 40 versions_sgpmichaelisvy
 
Object Oriented Programming-JAVA
Object Oriented Programming-JAVAObject Oriented Programming-JAVA
Object Oriented Programming-JAVAHome
 
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It PosesEnterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It PosesAlex Senkevitch
 

Similar to ドワンゴでのScala活用事例「ニコニコandroid」 (20)

Real World Android Akka
Real World Android AkkaReal World Android Akka
Real World Android Akka
 
Introduction and hacking OpenStack, Pycon India
Introduction and hacking OpenStack,  Pycon IndiaIntroduction and hacking OpenStack,  Pycon India
Introduction and hacking OpenStack, Pycon India
 
Java compilation
Java compilationJava compilation
Java compilation
 
What’s Slowing Down Your Kafka Pipeline? With Ruizhe Cheng and Pete Stevenson...
What’s Slowing Down Your Kafka Pipeline? With Ruizhe Cheng and Pete Stevenson...What’s Slowing Down Your Kafka Pipeline? With Ruizhe Cheng and Pete Stevenson...
What’s Slowing Down Your Kafka Pipeline? With Ruizhe Cheng and Pete Stevenson...
 
Eric Lafortune - The Jack and Jill build system
Eric Lafortune - The Jack and Jill build systemEric Lafortune - The Jack and Jill build system
Eric Lafortune - The Jack and Jill build system
 
Eric Lafortune - The Jack and Jill build system
Eric Lafortune - The Jack and Jill build systemEric Lafortune - The Jack and Jill build system
Eric Lafortune - The Jack and Jill build system
 
Play framework
Play frameworkPlay framework
Play framework
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)
 
Code Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCoCode Coverage Revised : EclEmma on JaCoCo
Code Coverage Revised : EclEmma on JaCoCo
 
0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlab0xdroid -- community-developed Android distribution by 0xlab
0xdroid -- community-developed Android distribution by 0xlab
 
Improve Android System Component Performance
Improve Android System Component PerformanceImprove Android System Component Performance
Improve Android System Component Performance
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
Spinnaker 파트 1
Spinnaker 파트 1Spinnaker 파트 1
Spinnaker 파트 1
 
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
2013.02.02 지앤선 테크니컬 세미나 - Xcode를 활용한 디버깅 팁(OSXDEV)
 
Guides To Analyzing WebKit Performance
Guides To Analyzing WebKit PerformanceGuides To Analyzing WebKit Performance
Guides To Analyzing WebKit Performance
 
Efficient mobile automation
Efficient mobile automationEfficient mobile automation
Efficient mobile automation
 
Building a modern SaaS in 2020
Building a modern SaaS in 2020Building a modern SaaS in 2020
Building a modern SaaS in 2020
 
Java 40 versions_sgp
Java 40 versions_sgpJava 40 versions_sgp
Java 40 versions_sgp
 
Object Oriented Programming-JAVA
Object Oriented Programming-JAVAObject Oriented Programming-JAVA
Object Oriented Programming-JAVA
 
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It PosesEnterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
Enterprise Java: Just What Is It and the Risks, Threats, and Exposures It Poses
 

ドワンゴでのScala活用事例「ニコニコandroid」