63
@ elmanu # playframework From PHP to the Play Framework in 3 months Manuel Bernhardt @elmanu http://manuel.bernhardt.io

Project Phoenix - From PHP to the Play Framework in 3 months

Embed Size (px)

DESCRIPTION

This is an experience report about Project Phoenix, aiming at porting a platform to the Play Framework with Scala in the short time period of 3 months. The presentation was given at Devoxx UK 2014

Citation preview

Page 1: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

From PHP to the Play Framework in 3 months

Manuel Bernhardt @elmanu http://manuel.bernhardt.io

Page 2: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Agenda

• Background

• Building the new platform

• Data migration

• Operations

• Summary & Future

Page 3: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Your speaker

•Freelance software consultant based in Vienna !

•Web, web, web

•Scala, Akka, Play Framework !

•Vienna Scala User Group !

•Open-Source

Page 4: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Agenda

• Background

• Building the new platform

• Data migration

• Operations

• Summary & Future

Page 5: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Talenthouse

•www.talenthouse.com !

•based in Los Angeles !

•connecting brands and artists !

•3+ million users

Page 6: Project Phoenix - From PHP to the Play Framework in 3 months
Page 7: Project Phoenix - From PHP to the Play Framework in 3 months
Page 8: Project Phoenix - From PHP to the Play Framework in 3 months
Page 9: Project Phoenix - From PHP to the Play Framework in 3 months
Page 10: Project Phoenix - From PHP to the Play Framework in 3 months
Page 11: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Background

•Problems with the old site

• Slow

• Developed by an external company

• Hard to evolve

Page 12: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Background

•Solution: new site!

• Scala

• Play Framework

• AngularJS

• elasticsearch

• …

Page 13: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Background

•A few interesting aspects

• Source code may not be available

• Data spread out in many places

• Only 3 months time

Page 14: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Background

•A few interesting aspects

• Source code may not be available

• Data spread out in many places

• Only 3 months time

Page 15: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Agenda

• Background

• Building the new platform

• Data migration

• Operations

• Methodologies & Tools

• Summary & Future

Page 16: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

Page 17: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

Page 18: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Page 19: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

• MVC framework !

• Compile as much as possible

• “Reactive”

Page 20: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

http://www.reactive-manifesto.org

Page 21: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Load balancer

Page 22: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Load balancer

Page 23: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

Data access?

Page 24: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

Anorm

Data access?

Squeryl

Page 25: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

Anorm

Data access?

Squeryl

Page 26: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

Anorm

Data access?

Squeryl

SORM Tiramisu

Page 27: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

• Started with Anorm

• Too verbose !

• Switched to Slick

• Plain SQL with neat string interpolation

• DSL for composing queries

Page 28: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

def fetchItemWithRelevanceSort(userId: Long, skip: Int, limit: Int)! (implicit s: Session): List[Item] = {! val q = for {! i <- items if !i.deleted! ! && i.visible_on_profile! ! && i.user_id === userId! } yield i! ! q.sortBy(item => (item.selected.desc, item.created_on.desc))! .drop(skip)! .take(limit)! .list!! }

Page 29: Project Phoenix - From PHP to the Play Framework in 3 months

val query = sql"""! with invites_for_market as (! select #$inviteSL, #$inviteMarketSL! from invite i! inner join invite_market im! on i.id = im.invite_id! and im.market_id = ${marketId.id}! where i.art_type = ${artType.toString}! and i.visibility_state = ${InviteVisibilityState.Public}! and i.deleted = false! order by i.submission_start desc, i.id desc! limit $limit! offset $skip! )!! select ifm.*, #$localInviteSL! from invites_for_market ifm! inner join local_invite li! on ifm.id = li.invite_id! and li.completed = true! order by ifm.submission_start desc, ifm.id asc! """! val queryResults = query.as[(Invite, InviteMarket, LocalInvite)].list!

Page 30: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

Front-end & UI

Page 31: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

Front-end & UI

Page 32: Project Phoenix - From PHP to the Play Framework in 3 months
Page 33: Project Phoenix - From PHP to the Play Framework in 3 months
Page 34: Project Phoenix - From PHP to the Play Framework in 3 months
Page 35: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

Front-end & UI

Page 36: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

• Recently open-sourced by Facebook !

• Virtual DOM, fast !

• Very easy to integrate in a page (less invasive than Angular)

ReactJS

Page 37: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

Front-end & UI

Page 38: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Building the new platform

• Build pipeline using gulp.js & bower !

• Assets pipeline

• LESS compilation

• JS minification

• Upload assets to Cloudfront

• Integrates translations from Crowdin

• Washes the dishes

Page 39: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Agenda

• Background

• Building the new platform

• Data migration

• Operations

• Summary & Future

Page 40: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration: source system(s)

Page 41: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration: source system(s)

Page 42: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration: source system(s)

Page 43: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration: source system(s)

Page 44: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration: source system(s)

Page 45: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration: source system(s)

Page 46: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration: source system(s)

Page 47: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration: source system(s)

Page 48: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration: migration schedule

Page 49: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration

• Akka to the rescue! !

• Concurrent user migration !

• Concurrent item migration

• Using Play’s WS library for async calls to Youtube and friends

Page 50: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration

User migrator

Worker Worker Worker Worker Worker

Page 51: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration

Item migrator

Page 52: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration

Item migrator

User item migrator

User item migrator

User item migrator

Page 53: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration

Item migrator

Item migration

worker

User item migrator

User item migrator

User item migrator

Item migration

worker

Item migration

worker

Item migration

worker

Item migration

worker

Item migration

worker

Page 54: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration

Item migrator

Item migration

worker

User item migrator

User item migrator

User item migrator

Item migration

worker

Item migration

worker

Item migration

worker

Item migration

worker

Item migration

worker

File fetcher

File fetcher

Page 55: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration

Item migrator

Item migration

worker

User item migrator

User item migrator

User item migrator

Item migration

worker

Item migration

worker

Item migration

worker

Item migration

worker

Item migration

worker

File fetcher

File fetcher

File uploader

File uploader

Page 56: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration

Item migrator

Item migration

worker

User item migrator

User item migrator

User item migrator

Item migration

worker

Item migration

worker

Item migration

worker

Item migration

worker

Item migration

worker

File fetcher

File fetcher

File uploader

Soundcloud worker

File uploader

Page 57: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Data migration

Page 58: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Agenda

• Background

• Building the new platform

• Data migration

• Operations

• Summary & Future

Page 59: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Operations

Operations

Page 60: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Operations

Page 61: Project Phoenix - From PHP to the Play Framework in 3 months

@YourTwitterHandle#DVXFR14{session hashtag} @elmanu#playframework

Summar

y

& Futu

re

Page 62: Project Phoenix - From PHP to the Play Framework in 3 months

@elmanu#playframework

Summary & Future

• Play Framework does not get in the way

• Easy to deploy and operate

• Many, many integrations !

• Many plans for the future

• Live activity feed

• Similarity search !

• Talenthouse is hiring!

Page 63: Project Phoenix - From PHP to the Play Framework in 3 months

@YourTwitterHandle#DVXFR14{session hashtag} @elmanu#playframework

Q & A