SlideShare a Scribd company logo
1 of 21
Download to read offline
Using Play Framework 2
in production
VSUG meetup 20.6.2013
Christian Papauschek
christian@miavia.in
Technology choice
• PHP, Java, C#, …
• Easy to find developers
• Big communities, lots of existing libraries
• Scala
• Hard to find developers
• More expressive, probably more productive
• A lot more fun
First steps with Play 2
on Startup Live (January 2013)
• IDE: IntelliJ IDEA
• Git Repo hosted on Dropbox
(yeah, I know…)
• Quickstart with Play 2 console
• Hotreload for development
• Packaged app and put it on EC2
What did we learn?
• Play is forgiving
• Learn it while being productive
• Adapt it to fit your needs
First production code
// Controller for landing pages
object Landing extends Controller {
// show main landing page
def showMain = Action {
implicit request =>
Ok(views.html.landing.main)
}
}
(conf/routes)
GET / controllers.Landing.showMain
(Landing.scala)
(main.scala.html)
[…]
Does it stay that simple?
Does it stay that simple?
Are you kidding me?
Serious production code
(if you spot a bug, let us know :D )
SEOAuthentication Caching DB AccessI18n
object Landing extends Controller {
// show main landing page
def landing(language: String) = RichAction {
implicit request => Translate(language, otherLang => routes.Landing.landing(otherLang)) {
implicit lang => {
// fetch featured authors and guides
val (guides, authors) = Cache.getOrElse("landing.guides")(
DB.default withSession {
implicit session: Session => {
(GuideItems.getFiltered(GuideFilter()), RichUsers.getAuthorSample)
}
})
Ok(views.html.landing.landing(
Random.shuffle(guides),
Random.shuffle(authors)))
}
}
}
}
Play fundamentals
// Controller for landing pages
object Landing extends Controller {
// show main landing page
def showMain = Action {
implicit request =>
Ok(views.html.landing.main)
}
}
(Landing.scala)
Request: contains requested URL, parameters, Cookies, etc.
Response: HTTP Response containing StatusCode, HTML/JSON/etc.
Action: something that takes a request, and returns a response
Action Composition
(how we extend the Play framework for DRYness)
// represents an abstract request that may or may not be authenticated
abstract class RichRequest[A](private val request: Request[A])
extends WrappedRequest(request) {
def maybeUserSession: Option[UserSession]
}
// non-authenticated request
case class DefaultRequest[A](maybeUserSession: Option[UserSession],
private val request: Request[A])
extends RichRequest[A](request)
// represents an authenticated request
case class AuthRequest[A](userSession: UserSession,
private val request: Request[A])
extends RichRequest[A](request)
// run action with authenticated user data, or default request data
object RichAction {
def apply[A](f: RichRequest[A] => Result) =
Action { request =>
Auth.check(request) match {
case Some(authRequest) => f(authRequest)
case _ => f(DefaultRequest(None, None, request))
}
}
}
Birds-eye view
Lots of libraries to integrate
Play Framework 2
Pitfalls
Mistake #1: CSS/less compilation
• Play uses Rhino, a library that runs JS in Java, to compile
less (it‘s very slow!)
• Switched to lessc compiler for production
• Switched to less.js during development
Mistake #2: HTTPS using Play 2
• Don‘t use Play/netty to handle SSL
• Now using nginx as reverse proxy
Mistake #3: Not managing Javascript
• First we hardcoded javascript routes
Eg. In Javascript: „$http.post(´/edit/guide/save`, ...)“
• Now:
• Javascript Routes
• JavascriptTranslations
• Javascript minification / compilation
Mistake #4: Configuring play for
synchronous code (Slick)
• Need to configure Play to have more threads
• Reuse of data access code
• Refactoring (where did I use this? Rename it!)
// filters guides which are visible on marketplace
def displayedGuides =
(for { g <- Guides if g.visible === 1 } yield g)
// return used category ids
def usedCategories(implicit session: Session) = (for {
g <- displayedGuides
cat <- GuideCategories if cat.guideId === g.id
} yield cat.categoryId).groupBy(id => id).map(g => g._1).list
• write Scala that’s compiled to SQL
• keeps your database queries DRY
Why Play 2?
Retrospective
• Readable codebase: Learn idiomatic Scala while being
productive!
• Has everything you need built in, but allows you to throw
everything out piece by piece as you have more advanced
requirements (less compilation, templates, etc.)
• DRY
• Play is (relatively) fast.
How fast? Google „TechEmpower Performance benchmarks“
Summary:Why Play 2?
• We know that code-bases eventually grow big. Scala helps.
• Took the good stuff from other successful frameworks such as Ruby on Rails.
„Embraces HTTP“
Adopted byTypesafe as de-facto standard web framework for Scala
• As a startup: attract people who want to learn and find better ways to
develop in the web.
• Scala as a new and powerful, but stable language
• Play 2 as a bleeding edge, but amazingly stable framework
• For other languages/frameworks you might find more developers, but
Scala acts as a good filter to find the good ones.

More Related Content

What's hot

GitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by ScalaGitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by Scalatakezoe
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Matthew Groves
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Ryan Cuprak
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring BootTrey Howard
 
Take control. write a plugin. part II
Take control. write a plugin. part IITake control. write a plugin. part II
Take control. write a plugin. part IIBaruch Sadogursky
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Yevgeniy Brikman
 
Workshop Framework(J2EE/OSGi/RCP)
Workshop Framework(J2EE/OSGi/RCP)Workshop Framework(J2EE/OSGi/RCP)
Workshop Framework(J2EE/OSGi/RCP)Summer Lu
 
Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...
Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...
Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...Sla Va
 
Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Pavel Kaminsky
 
Intro to JavaScript Tooling in Visual Studio Code
Intro to JavaScript Tooling in Visual Studio CodeIntro to JavaScript Tooling in Visual Studio Code
Intro to JavaScript Tooling in Visual Studio CodeColdFusionConference
 
Play vs Grails Smackdown - Devoxx France 2013
Play vs Grails Smackdown - Devoxx France 2013Play vs Grails Smackdown - Devoxx France 2013
Play vs Grails Smackdown - Devoxx France 2013Matt Raible
 
Play framework 2 : Peter Hilton
Play framework 2 : Peter HiltonPlay framework 2 : Peter Hilton
Play framework 2 : Peter HiltonJAX London
 
Java Development EcoSystem
Java Development EcoSystemJava Development EcoSystem
Java Development EcoSystemAlex Tumanoff
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS LimitationsValeri Karpov
 
Playframework + Twitter Bootstrap
Playframework + Twitter BootstrapPlayframework + Twitter Bootstrap
Playframework + Twitter BootstrapKevingo Tsai
 

What's hot (20)

Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
GitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by ScalaGitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by Scala
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Take control. write a plugin. part II
Take control. write a plugin. part IITake control. write a plugin. part II
Take control. write a plugin. part II
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)
 
Apache Lucene for Java EE Developers
Apache Lucene for Java EE DevelopersApache Lucene for Java EE Developers
Apache Lucene for Java EE Developers
 
Workshop Framework(J2EE/OSGi/RCP)
Workshop Framework(J2EE/OSGi/RCP)Workshop Framework(J2EE/OSGi/RCP)
Workshop Framework(J2EE/OSGi/RCP)
 
Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...
Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...
Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...
 
Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments
 
Intro to JavaScript Tooling in Visual Studio Code
Intro to JavaScript Tooling in Visual Studio CodeIntro to JavaScript Tooling in Visual Studio Code
Intro to JavaScript Tooling in Visual Studio Code
 
Play vs Grails Smackdown - Devoxx France 2013
Play vs Grails Smackdown - Devoxx France 2013Play vs Grails Smackdown - Devoxx France 2013
Play vs Grails Smackdown - Devoxx France 2013
 
Play framework 2 : Peter Hilton
Play framework 2 : Peter HiltonPlay framework 2 : Peter Hilton
Play framework 2 : Peter Hilton
 
Java Development EcoSystem
Java Development EcoSystemJava Development EcoSystem
Java Development EcoSystem
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Java and XPages
Java and XPagesJava and XPages
Java and XPages
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
 
Playframework + Twitter Bootstrap
Playframework + Twitter BootstrapPlayframework + Twitter Bootstrap
Playframework + Twitter Bootstrap
 
Powershell training material
Powershell training materialPowershell training material
Powershell training material
 

Similar to Using Play Framework 2 in production

Java Code Generation for Productivity
Java Code Generation for ProductivityJava Code Generation for Productivity
Java Code Generation for ProductivityDavid Noble
 
Google App Engine With Java And Groovy
Google App Engine With Java And GroovyGoogle App Engine With Java And Groovy
Google App Engine With Java And GroovyKen Kousen
 
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
Build an AI/ML-driven image archive processing workflow: Image archive, analy...Build an AI/ML-driven image archive processing workflow: Image archive, analy...
Build an AI/ML-driven image archive processing workflow: Image archive, analy...wesley chun
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsSadayuki Furuhashi
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and DesktopElizabeth Smith
 
Jquery dojo slides
Jquery dojo slidesJquery dojo slides
Jquery dojo slideshelenmga
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryAlek Davis
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Let's build Developer Portal with Backstage
Let's build Developer Portal with BackstageLet's build Developer Portal with Backstage
Let's build Developer Portal with BackstageOpsta
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Exploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScriptExploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScriptwesley chun
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
GQuery a jQuery clone for Gwt, RivieraDev 2011
GQuery a jQuery clone for Gwt, RivieraDev 2011GQuery a jQuery clone for Gwt, RivieraDev 2011
GQuery a jQuery clone for Gwt, RivieraDev 2011Manuel Carrasco Moñino
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Adam Tomat
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup PerformanceGreg Whalin
 

Similar to Using Play Framework 2 in production (20)

Java Code Generation for Productivity
Java Code Generation for ProductivityJava Code Generation for Productivity
Java Code Generation for Productivity
 
Google App Engine With Java And Groovy
Google App Engine With Java And GroovyGoogle App Engine With Java And Groovy
Google App Engine With Java And Groovy
 
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
Build an AI/ML-driven image archive processing workflow: Image archive, analy...Build an AI/ML-driven image archive processing workflow: Image archive, analy...
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
Nodejs - A quick tour (v4)
Nodejs - A quick tour (v4)Nodejs - A quick tour (v4)
Nodejs - A quick tour (v4)
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and Desktop
 
Jquery dojo slides
Jquery dojo slidesJquery dojo slides
Jquery dojo slides
 
Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)Nodejs - A quick tour (v5)
Nodejs - A quick tour (v5)
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Dart Workshop
Dart WorkshopDart Workshop
Dart Workshop
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
End-to-end testing with geb
End-to-end testing with gebEnd-to-end testing with geb
End-to-end testing with geb
 
Let's build Developer Portal with Backstage
Let's build Developer Portal with BackstageLet's build Developer Portal with Backstage
Let's build Developer Portal with Backstage
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Exploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScriptExploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScript
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
GQuery a jQuery clone for Gwt, RivieraDev 2011
GQuery a jQuery clone for Gwt, RivieraDev 2011GQuery a jQuery clone for Gwt, RivieraDev 2011
GQuery a jQuery clone for Gwt, RivieraDev 2011
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 

Recently uploaded

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 

Recently uploaded (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

Using Play Framework 2 in production

  • 1. Using Play Framework 2 in production VSUG meetup 20.6.2013 Christian Papauschek christian@miavia.in
  • 2.
  • 3. Technology choice • PHP, Java, C#, … • Easy to find developers • Big communities, lots of existing libraries • Scala • Hard to find developers • More expressive, probably more productive • A lot more fun
  • 4. First steps with Play 2 on Startup Live (January 2013) • IDE: IntelliJ IDEA • Git Repo hosted on Dropbox (yeah, I know…) • Quickstart with Play 2 console • Hotreload for development • Packaged app and put it on EC2
  • 5. What did we learn? • Play is forgiving • Learn it while being productive • Adapt it to fit your needs
  • 6. First production code // Controller for landing pages object Landing extends Controller { // show main landing page def showMain = Action { implicit request => Ok(views.html.landing.main) } } (conf/routes) GET / controllers.Landing.showMain (Landing.scala) (main.scala.html) […]
  • 7. Does it stay that simple?
  • 8. Does it stay that simple? Are you kidding me?
  • 9. Serious production code (if you spot a bug, let us know :D ) SEOAuthentication Caching DB AccessI18n object Landing extends Controller { // show main landing page def landing(language: String) = RichAction { implicit request => Translate(language, otherLang => routes.Landing.landing(otherLang)) { implicit lang => { // fetch featured authors and guides val (guides, authors) = Cache.getOrElse("landing.guides")( DB.default withSession { implicit session: Session => { (GuideItems.getFiltered(GuideFilter()), RichUsers.getAuthorSample) } }) Ok(views.html.landing.landing( Random.shuffle(guides), Random.shuffle(authors))) } } } }
  • 10.
  • 11. Play fundamentals // Controller for landing pages object Landing extends Controller { // show main landing page def showMain = Action { implicit request => Ok(views.html.landing.main) } } (Landing.scala) Request: contains requested URL, parameters, Cookies, etc. Response: HTTP Response containing StatusCode, HTML/JSON/etc. Action: something that takes a request, and returns a response
  • 12. Action Composition (how we extend the Play framework for DRYness) // represents an abstract request that may or may not be authenticated abstract class RichRequest[A](private val request: Request[A]) extends WrappedRequest(request) { def maybeUserSession: Option[UserSession] } // non-authenticated request case class DefaultRequest[A](maybeUserSession: Option[UserSession], private val request: Request[A]) extends RichRequest[A](request) // represents an authenticated request case class AuthRequest[A](userSession: UserSession, private val request: Request[A]) extends RichRequest[A](request) // run action with authenticated user data, or default request data object RichAction { def apply[A](f: RichRequest[A] => Result) = Action { request => Auth.check(request) match { case Some(authRequest) => f(authRequest) case _ => f(DefaultRequest(None, None, request)) } } }
  • 13. Birds-eye view Lots of libraries to integrate
  • 15. Mistake #1: CSS/less compilation • Play uses Rhino, a library that runs JS in Java, to compile less (it‘s very slow!) • Switched to lessc compiler for production • Switched to less.js during development
  • 16. Mistake #2: HTTPS using Play 2 • Don‘t use Play/netty to handle SSL • Now using nginx as reverse proxy
  • 17. Mistake #3: Not managing Javascript • First we hardcoded javascript routes Eg. In Javascript: „$http.post(´/edit/guide/save`, ...)“ • Now: • Javascript Routes • JavascriptTranslations • Javascript minification / compilation
  • 18. Mistake #4: Configuring play for synchronous code (Slick) • Need to configure Play to have more threads • Reuse of data access code • Refactoring (where did I use this? Rename it!)
  • 19. // filters guides which are visible on marketplace def displayedGuides = (for { g <- Guides if g.visible === 1 } yield g) // return used category ids def usedCategories(implicit session: Session) = (for { g <- displayedGuides cat <- GuideCategories if cat.guideId === g.id } yield cat.categoryId).groupBy(id => id).map(g => g._1).list • write Scala that’s compiled to SQL • keeps your database queries DRY
  • 20. Why Play 2? Retrospective • Readable codebase: Learn idiomatic Scala while being productive! • Has everything you need built in, but allows you to throw everything out piece by piece as you have more advanced requirements (less compilation, templates, etc.) • DRY • Play is (relatively) fast. How fast? Google „TechEmpower Performance benchmarks“
  • 21. Summary:Why Play 2? • We know that code-bases eventually grow big. Scala helps. • Took the good stuff from other successful frameworks such as Ruby on Rails. „Embraces HTTP“ Adopted byTypesafe as de-facto standard web framework for Scala • As a startup: attract people who want to learn and find better ways to develop in the web. • Scala as a new and powerful, but stable language • Play 2 as a bleeding edge, but amazingly stable framework • For other languages/frameworks you might find more developers, but Scala acts as a good filter to find the good ones.