This document discusses using the Play Framework for web application development on Google App Engine (GAE). It provides an overview of Play and GAE, how they work together, and some tradeoffs. Specifically, it covers how Play abstracts away the GAE infrastructure, limitations of the GAE sandbox environment, options for running Play 2 applications on GAE including using a WAR file or custom runtime, and the pros and cons of the Play Framework on GAE approach.
3. smart.biz.plsmart.biz.pl
❖ App Engine intro, scaling & limitations
❖ Play Framework stuff
❖ GAE abstraction
❖ How do this two things work together
❖ Play 2 on GAE?
❖ Trade-offs
3
Play Framework + GAE
8. smart.biz.pl
Scaling is simplified
8
One tier of servers
Instances:
- capacity
- max / min #
- manual / autoscale
- warm up /
decommission
- traffic splitting
Internet
10. smart.biz.pl
GAE Limitations
10
Security sandbox
● Java class whitelist
● Java 7
● Servlet API 2.5
○ no real async WS calls
● No raw socket connections
○ no SMTP etc.
○ Url Fetch service instead
Scalability
● Frontend calls are limited to
30s
● Scheduled Jobs limited to
10min
● Url Fetch limited to max 60s
● Do not share object in session
● NoSQL datastore *
● 200 indexes
13. smart.biz.pl
Play 1 Play 2
2008 released 2013
Java first service Scala first, Java
Groovy templates Scala
1 GAE module -
by community
maintenance mode*
developed
by authors
and community
by 3rd part. commerce support
by authors
and 3rd part.
Play Framework versions
13
14. smart.biz.pl
There is no HttpServletRequest, HttpSession etc.
Not a JEE Framework
14
GAE module wraps Play app into .war file
16. smart.biz.plsmart.biz.pl
#pass value to next request in flash scope
flash.put(“key”, object);
#store in encrypted user cookie, Strings only, 4kb
session.put(“key”, “value”);
#store object in cache
Cache.store(“key”, object, “1h”);
16
Share Nothing
22. smart.biz.plsmart.biz.pl
public class Employee extends Model {
@Id public Long id;
public String fullName;
public Department dep;
}
public class Department extends Model {
@Id public Long id;
@Url public String website;
public Date launched;
}
22
Data store abstraction
24. smart.biz.plsmart.biz.pl
public class Employee extends Model {
@Id public Long id;
public String fullName;
#no Joins, dep stores only id field
public Department dep;
#retrieves and maps into object
public String getDepWebsite() {
#dep.website is null until you call .get()
return dep.get().website;
}
}
24
Fetching data, no joins
25. smart.biz.plsmart.biz.pl
public class Employee extends Model {...
public static List<Employee> getAll(Long depId) {
return all().filter(“dep”, new Department(depId))
.fetch();
}
public static Query<Employee> all() {
return all(Employee.class);
}
25
Querying
27. smart.biz.plsmart.biz.pl
#http method, app url (regex), controller method
GET /employee/{id} Employees.user
POST /employee/ Employees.create
PUT /employee/{id} Employees.update
DELETE /employee/{id} Employees.delete
GET /employee/show-{id} Employees.show
GET /employee/list Employees.list
27
Routing
28. smart.biz.plsmart.biz.pl
#controller methods are static for Play v. < 1.4
public class Employees extends App {
public static void create(Employee em) {
em.save();
show(em.id); #HTTP 302 redirect
}
#template is chosen by convention
public static void show(Long id) {
#object passed into Employees/show.html
render(Employee.get(id));
}
public static void list() {
renderJSON(Employee.all());
}
}
28
Controller
34. smart.biz.pl
Trade-offs
34
Pros
● Faster deployment
● Scaling
● Google Infrastructure
● maintenance + analytic tools
○ BigQuery etc.
● Abstraction
○ You are not tied with
GAE SDK
Cons
● Sandbox limitations
● Not truly asynchronous on
basic GAE
● Servlet container lowers
application performance
● Watch out for test coverage