75
Sunday, March 10, 13

From a monolithic Ruby on Rails app to the JVM

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: From a monolithic  Ruby on Rails app  to the JVM

Sunday, March 10, 13

Page 2: From a monolithic  Ruby on Rails app  to the JVM

From a monolithic Ruby on Rails app

to the JVM

phil calçado@pcalcado

http://philcalcado.com

JDC2013 - CairoSunday, March 10, 13

Page 3: From a monolithic  Ruby on Rails app  to the JVM

2011: Phil decides to move to Berlin

Sunday, March 10, 13

Page 4: From a monolithic  Ruby on Rails app  to the JVM

Sunday, March 10, 13

Page 5: From a monolithic  Ruby on Rails app  to the JVM

Sunday, March 10, 13

Page 6: From a monolithic  Ruby on Rails app  to the JVM

Sunday, March 10, 13

Page 7: From a monolithic  Ruby on Rails app  to the JVM

Sunday, March 10, 13

Page 8: From a monolithic  Ruby on Rails app  to the JVM

Growing a product is awesome

Sunday, March 10, 13

Page 9: From a monolithic  Ruby on Rails app  to the JVM

http://bit.ly/building-the-next-soundcloud

Sunday, March 10, 13

Page 10: From a monolithic  Ruby on Rails app  to the JVM

Sunday, March 10, 13

Page 11: From a monolithic  Ruby on Rails app  to the JVM

Sunday, March 10, 13

Page 12: From a monolithic  Ruby on Rails app  to the JVM

~ 180 million users / month

> 10 hours of audio uploaded every minute

Sunday, March 10, 13

Page 13: From a monolithic  Ruby on Rails app  to the JVM

But scaling is hard.

Sunday, March 10, 13

Page 14: From a monolithic  Ruby on Rails app  to the JVM

SoundCloud was born on Rails

It allowed us to iterate real fast and keep

code quality up(-ish).Sunday, March 10, 13

Page 15: From a monolithic  Ruby on Rails app  to the JVM

Controller

ActiveRecord Model

Database

Rails is simple.

Sunday, March 10, 13

Page 16: From a monolithic  Ruby on Rails app  to the JVM

Controller

ActiveRecord Model

Database

Rails is simple.

If you want to write a toy blog engine.

Sunday, March 10, 13

Page 17: From a monolithic  Ruby on Rails app  to the JVM

Controller

ActiveRecord Model

Database

In the real world, it gets messy.

Sunday, March 10, 13

Page 18: From a monolithic  Ruby on Rails app  to the JVM

Controller

ActiveRecord Model

Database

DelayedJobs

Memcached

EventMachine

sc-caching

sc-logging

lhm

statsy new relic

nokogiri

mysql master/slave adapter

haml

thin

amqp

yajl

In the real world, it gets messy.

Real messy.Sunday, March 10, 13

Page 19: From a monolithic  Ruby on Rails app  to the JVM

Scaling Rails is hard(er).

Sunday, March 10, 13

Page 20: From a monolithic  Ruby on Rails app  to the JVM

No concurrency? 1) Spawn A LOT of

processes.

Sunday, March 10, 13

Page 21: From a monolithic  Ruby on Rails app  to the JVM

No concurrency? 1) Spawn A LOT of

processes.2) Make everything a

background job

Sunday, March 10, 13

Page 22: From a monolithic  Ruby on Rails app  to the JVM

No Virtual Machine?Adapt your deployment to > 1 minute application

bootstrap time

Sunday, March 10, 13

Page 23: From a monolithic  Ruby on Rails app  to the JVM

No proper Garbage Collection?

Get used to restarting processes. Frequently.

Sunday, March 10, 13

Page 24: From a monolithic  Ruby on Rails app  to the JVM

Scaling Rails development is hard.

Sunday, March 10, 13

Page 25: From a monolithic  Ruby on Rails app  to the JVM

Idiomatic in Rails:

Sunday, March 10, 13

Page 26: From a monolithic  Ruby on Rails app  to the JVM

Idiomatic in Rails:

Just like Java circa 2004

Sunday, March 10, 13

Page 27: From a monolithic  Ruby on Rails app  to the JVM

Understanding the Rails mindset:

http://bit.ly/not-a-virtue

Sunday, March 10, 13

Page 28: From a monolithic  Ruby on Rails app  to the JVM

Understanding the Rails mindset:

i do not think it means what you think it

meanshttp://bit.ly/not-a-virtue

Sunday, March 10, 13

Page 29: From a monolithic  Ruby on Rails app  to the JVM

If you are injecting aggregation or composition you are Doing it Wrong(tm)

Sunday, March 10, 13

Page 30: From a monolithic  Ruby on Rails app  to the JVM

Idiomatic in Rails:

Sunday, March 10, 13

Page 31: From a monolithic  Ruby on Rails app  to the JVM

Understanding the Rails mindset:

http://bit.ly/trashable

Sunday, March 10, 13

Page 32: From a monolithic  Ruby on Rails app  to the JVM

Understanding the Rails mindset:

http://bit.ly/trashable

Just like aop, but even worse

Sunday, March 10, 13

Page 33: From a monolithic  Ruby on Rails app  to the JVM

Idiomatic in Rails:

Sunday, March 10, 13

Page 34: From a monolithic  Ruby on Rails app  to the JVM

Idiomatic in Rails:

no real complexity or loC reduction

Sunday, March 10, 13

Page 35: From a monolithic  Ruby on Rails app  to the JVM

Controller

ActiveRecord Model

Database

Rails is simple.

If you want to write a toy blog engine.

Sunday, March 10, 13

Page 36: From a monolithic  Ruby on Rails app  to the JVM

Effectively, controllers have a lot of logic

Controller

ActiveRecord Model

Database

Sunday, March 10, 13

Page 37: From a monolithic  Ruby on Rails app  to the JVM

Effectively, controllers have a lot of logic

But so do models!

Controller

ActiveRecord Model

Database

Sunday, March 10, 13

Page 38: From a monolithic  Ruby on Rails app  to the JVM

Where do we go from here?

Sunday, March 10, 13

Page 39: From a monolithic  Ruby on Rails app  to the JVM

We will not do Java.

Sunday, March 10, 13

Page 40: From a monolithic  Ruby on Rails app  to the JVM

We, the Java community, screwed up

Focused on the “Enterprise” while nimbler companies took over

Sunday, March 10, 13

Page 41: From a monolithic  Ruby on Rails app  to the JVM

We, the Java community, screwed up

Tried to solve core problems with more complicated tooling

Sunday, March 10, 13

Page 42: From a monolithic  Ruby on Rails app  to the JVM

We, the Java community, screwed up

JSF, Portlets, JavaFx, Oracle vs. Android: the joke is on us

Sunday, March 10, 13

Page 43: From a monolithic  Ruby on Rails app  to the JVM

But we will do the JVM.

Sunday, March 10, 13

Page 44: From a monolithic  Ruby on Rails app  to the JVM

Who cares about Oracle/JCP?

So many modern languages. None are “official”.

Sunday, March 10, 13

Page 45: From a monolithic  Ruby on Rails app  to the JVM

Who cares about Oracle/JCP?

It is crazy to use “Enterprise” middleware at scale.

Sunday, March 10, 13

Page 46: From a monolithic  Ruby on Rails app  to the JVM

Who cares about Oracle/JCP?

twitter, Tumblr, Foursquare, Netflix, Facebook, typesafe, etc. are the new powerhouses.

Sunday, March 10, 13

Page 47: From a monolithic  Ruby on Rails app  to the JVM

Options:1) Non-Rails Ruby2) Scala4) Clojure

Sunday, March 10, 13

Page 48: From a monolithic  Ruby on Rails app  to the JVM

Non-Rails Ruby

+ Simple+ Easy to hire engineers+ Lingua-franca inside SC- Most code not thread-safe- Lots of native code- Rails mindset everywhere

Sunday, March 10, 13

Page 49: From a monolithic  Ruby on Rails app  to the JVM

Scala

+ “twitter stack” (Finagle, docs)+ Good Java interop+ Static typing+ Good engineering practices starting to emerge- Binary compatibility- Can get complicated

Sunday, March 10, 13

Page 50: From a monolithic  Ruby on Rails app  to the JVM

Clojure

+ Easier to get started with+ Favours smaller apps + Good Java interop- Very early days for engineering good practices- 3rd party libs a bit off in quality

Sunday, March 10, 13

Page 51: From a monolithic  Ruby on Rails app  to the JVM

Integrating Clojure with Jetty

Sunday, March 10, 13

Page 52: From a monolithic  Ruby on Rails app  to the JVM

Async I/O with Scala/Finagle

Sunday, March 10, 13

Page 53: From a monolithic  Ruby on Rails app  to the JVM

Let’s try them all.

Sunday, March 10, 13

Page 54: From a monolithic  Ruby on Rails app  to the JVM

Enabling

Sunday, March 10, 13

Page 55: From a monolithic  Ruby on Rails app  to the JVM

1) Micro-services

- A couple of thousand LOC- Once you grasp the domain, can be rewritten in ~1 week- Reduces risk in trying new things

Sunday, March 10, 13

Page 56: From a monolithic  Ruby on Rails app  to the JVM

Legacy Application(Rails)

Database

internet

Sunday, March 10, 13

Page 57: From a monolithic  Ruby on Rails app  to the JVM

Stats

MessagingRecommenderSettingsNotifications

Sounds Users Stream

Sunday, March 10, 13

Page 58: From a monolithic  Ruby on Rails app  to the JVM

Stats

DB

Messaging

DB

Recommender

DB

Settings

DB

Notifications

DB

Sounds

DB

Users

DB

Stream

DB

Sunday, March 10, 13

Page 59: From a monolithic  Ruby on Rails app  to the JVM

Stats

MessagingRecommenderSettingsNotifications

Sounds Users Stream

API

internet

Sunday, March 10, 13

Page 60: From a monolithic  Ruby on Rails app  to the JVM

2) Easy to deploy

- Old Rails system has fully automated deployment- From change to production should take minutes- Integrated to CI- Reverting is easy

Sunday, March 10, 13

Page 61: From a monolithic  Ruby on Rails app  to the JVM

Sunday, March 10, 13

Page 62: From a monolithic  Ruby on Rails app  to the JVM

Sunday, March 10, 13

Page 63: From a monolithic  Ruby on Rails app  to the JVM

Sunday, March 10, 13

Page 64: From a monolithic  Ruby on Rails app  to the JVM

Sunday, March 10, 13

Page 65: From a monolithic  Ruby on Rails app  to the JVM

Current status

- ~6 new or extracted systems- 3 Clojure- 1 Scala- 2 JRuby

Sunday, March 10, 13

Page 66: From a monolithic  Ruby on Rails app  to the JVM

Current status

Rule of thumb: 1 JVM = 10 thins

Sunday, March 10, 13

Page 67: From a monolithic  Ruby on Rails app  to the JVM

main takeaways

Sunday, March 10, 13

Page 68: From a monolithic  Ruby on Rails app  to the JVM

Rails, PHP, etc. are a very good choice to start something

Sunday, March 10, 13

Page 69: From a monolithic  Ruby on Rails app  to the JVM

You need to know when to migrate away

Sunday, March 10, 13

Page 70: From a monolithic  Ruby on Rails app  to the JVM

Build infrastructure to reduce the risk of trying new things

Sunday, March 10, 13

Page 71: From a monolithic  Ruby on Rails app  to the JVM

The JVM is still the best multi-language VM out there

Sunday, March 10, 13

Page 72: From a monolithic  Ruby on Rails app  to the JVM

There is a lot of JVM-related stuff happening outside

the official channels

Sunday, March 10, 13

Page 73: From a monolithic  Ruby on Rails app  to the JVM

Even if you are doing Java, drop the extra weight

Sunday, March 10, 13

Page 74: From a monolithic  Ruby on Rails app  to the JVM

Java is the new C

Sunday, March 10, 13

Page 75: From a monolithic  Ruby on Rails app  to the JVM

phil calçado

http://philcalcado.com@pcalcado

www.soundcloud.com

Sunday, March 10, 13