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
Using Play Framework 2 in production
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)))
}
}
}
}
Using Play Framework 2 in production
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

2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdfThe Good Food Institute
 
UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2DianaGray10
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxNeo4j
 
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveKeep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveIES VE
 
Technical SEO for Improved Accessibility WTS FEST
Technical SEO for Improved Accessibility  WTS FESTTechnical SEO for Improved Accessibility  WTS FEST
Technical SEO for Improved Accessibility WTS FESTBillieHyde
 
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Alkin Tezuysal
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTopCSSGallery
 
UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3DianaGray10
 
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechWebinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechProduct School
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosErol GIRAUDY
 
The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)codyslingerland1
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and businessFrancesco Corti
 
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptxEmil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptxNeo4j
 
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNeo4j
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1DianaGray10
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInThousandEyes
 
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl
 
How to release an Open Source Dataweave Library
How to release an Open Source Dataweave LibraryHow to release an Open Source Dataweave Library
How to release an Open Source Dataweave Libraryshyamraj55
 

Recently uploaded (20)

2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf
 
UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2UiPath Studio Web workshop series - Day 2
UiPath Studio Web workshop series - Day 2
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
 
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveKeep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
 
Technical SEO for Improved Accessibility WTS FEST
Technical SEO for Improved Accessibility  WTS FESTTechnical SEO for Improved Accessibility  WTS FEST
Technical SEO for Improved Accessibility WTS FEST
 
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
Design and Modeling for MySQL SCALE 21X Pasadena, CA Mar 2024
 
Top 10 Squarespace Development Companies
Top 10 Squarespace Development CompaniesTop 10 Squarespace Development Companies
Top 10 Squarespace Development Companies
 
UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3UiPath Studio Web workshop Series - Day 3
UiPath Studio Web workshop Series - Day 3
 
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - TechWebinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
Webinar: The Art of Prioritizing Your Product Roadmap by AWS Sr PM - Tech
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenarios
 
The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and business
 
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptxEmil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
 
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4j
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
 
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile Brochure
 
How to release an Open Source Dataweave Library
How to release an Open Source Dataweave LibraryHow to release an Open Source Dataweave Library
How to release an Open Source Dataweave Library
 

Using Play Framework 2 in production

  • 1. Using Play Framework 2 in production VSUG meetup 20.6.2013 Christian Papauschek christian@miavia.in
  • 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))) } } } }
  • 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.