taming monolithic monsters

71
@gavinjoyce Taming Monolithic Monsters

Upload: gavinjoyce

Post on 21-Dec-2014

402 views

Category:

Technology


1 download

DESCRIPTION

The slides from my presentation to RubyIreland

TRANSCRIPT

Page 1: Taming monolithic monsters

@gavinjoyce

Taming Monolithic Monsters

Page 2: Taming monolithic monsters

Need help building something ambitious?

[email protected]

Page 3: Taming monolithic monsters

What’s the Problem?

Page 4: Taming monolithic monsters

What’s the Problem?● Rails apps don’t scale

Page 5: Taming monolithic monsters

What’s the Problem?● Rails apps don’t scale● Rails apps do scale:

Page 6: Taming monolithic monsters

What’s the Problem?● Rails apps don’t scale● Rails apps do scale:

○ Web servers are cheap

Page 7: Taming monolithic monsters

What’s the Problem?● Rails apps don’t scale● Rails apps do scale:

○ Web servers are cheap○ Engineers are expensive

Page 8: Taming monolithic monsters

What’s the Problem?● Rails apps don’t scale● Rails apps do scale:

○ Web servers are cheap○ Engineers are expensive○ Rails is optimised to save engineering time

Page 9: Taming monolithic monsters

What’s the Problem?● Rails apps don’t scale● Rails apps do scale:

○ Web servers are cheap○ Engineers are expensive○ Rails is optimised to save engineering time○ not the full story...

Page 10: Taming monolithic monsters

What’s the Problem?

● Large rails apps are hard to scale

In my experience:

Page 11: Taming monolithic monsters

What’s the Problem?

● Large rails apps are hard to scale:○ Team size

In my experience:

Page 12: Taming monolithic monsters

What’s the Problem?

● Large rails apps are hard to scale:○ Team size

■ code base complexity

In my experience:

Page 13: Taming monolithic monsters

What’s the Problem?

● Large rails apps are hard to scale:○ Team size

■ code base complexity■ brittleness due to tight coupling between

models

In my experience:

Page 14: Taming monolithic monsters

What’s the Problem?

● Large rails apps are hard to scale:○ Team size

■ code base complexity■ brittleness due to tight coupling between

models○ TDD feedback time

In my experience:

Page 15: Taming monolithic monsters

Mutations Gemgithub.com/cypriss/mutations

Page 16: Taming monolithic monsters

Mutations Gemgithub.com/cypriss/mutations

● Compose your business logic into commands that sanitize and validate input

Page 17: Taming monolithic monsters

Mutations Gemgithub.com/cypriss/mutations

● Compose your business logic into commands that sanitize and validate input

● Write safe, reusable, and maintainable code for Ruby and Rails apps

Page 18: Taming monolithic monsters

Defining a Mutations Command

Page 19: Taming monolithic monsters

Using a Mutations Command

Page 20: Taming monolithic monsters

demo - simple mutation command

Page 21: Taming monolithic monsters

Mutations in your app

Page 22: Taming monolithic monsters

Mutations in your app

● create an internal api

Page 23: Taming monolithic monsters

Mutations in your app

● create an internal api○ logically isolate key business logic

Page 24: Taming monolithic monsters

Mutations in RestPack

Page 25: Taming monolithic monsters

Mutations in RestPack

https://github.com/restpack

Page 26: Taming monolithic monsters

Mutations in RestPack

Page 27: Taming monolithic monsters

Mutations in RestPack

● Services are packaged as gems

Page 28: Taming monolithic monsters

Mutations in RestPack

● Services are packaged as gems:○ Commands

Page 29: Taming monolithic monsters

Mutations in RestPack

● Services are packaged as gems:○ Commands○ Serialisers

Page 30: Taming monolithic monsters

Mutations in RestPack

● Services are packaged as gems:○ Commands○ Serialisers○ Models

Page 31: Taming monolithic monsters

Mutations in RestPack

● Services are packaged as gems:○ Commands○ Serialisers○ Models○ Migrations

Page 32: Taming monolithic monsters

Mutations in RestPack

● Services are packaged as gems:○ Commands○ Serialisers○ Models○ Migrations○ Specs

Page 33: Taming monolithic monsters

Mutations in RestPack

● Services are packaged as gems:○ Commands○ Serialisers○ Models○ Migrations○ Specs

● Commands are the public interface

Page 34: Taming monolithic monsters

Mutations in RestPack

● Services are packaged as gems:○ Commands○ Serialisers○ Models○ Migrations○ Specs

● Commands are the public interface○ either Ruby or REST

Page 35: Taming monolithic monsters

RestPack Service Gem Anatomy

Page 36: Taming monolithic monsters

DB

RestPack Service Gem Anatomy

Page 37: Taming monolithic monsters

DB

RestPack Service Gem Anatomy

rake restpack:migrate

Page 38: Taming monolithic monsters

DB

models

RestPack Service Gem Anatomy

rake restpack:migrate

Page 39: Taming monolithic monsters

DB

models

RestPack Service Gem Anatomy

ActiveRecord models

rake restpack:migrate

Page 40: Taming monolithic monsters

DB

models

serialisers

RestPack Service Gem Anatomy

rake restpack:migrate

ActiveRecord models

Page 41: Taming monolithic monsters

DB

models

serialisers

RestPack Service Gem Anatomy

RestPack::Serializer gem

rake restpack:migrate

ActiveRecord models

Page 42: Taming monolithic monsters

DB

models

serialisers

commands

RestPack Service Gem Anatomy

rake restpack:migrate

ActiveRecord models

RestPack::Serializer gem

Page 43: Taming monolithic monsters

DB

models

serialisers

commands

RestPack Service Gem Anatomy

Mutations gem

rake restpack:migrate

ActiveRecord models

RestPack::Serializer gem

Page 44: Taming monolithic monsters

RestPack Service Gem Anatomy

code demo - restpack_activity_service

https://github.com/RestPack/restpack_activity_service

Page 45: Taming monolithic monsters

Using service gems from Rails

A first attempt….

Page 46: Taming monolithic monsters

DB

Activity Service Gem

Page 47: Taming monolithic monsters

actv.io rails app

DB

Activity Controller

Activity Service Gem

Host Ruby Application

Page 48: Taming monolithic monsters

actv.io rails app

DB

Activity Controller

Activity Clent Gem

Activity Service Gem

Host Ruby Application

Page 49: Taming monolithic monsters

actv.io rails app

Activity Model

DB

Activity Controller

Activity Clent Gem

Activity Service Gem

Host Ruby Application

Page 50: Taming monolithic monsters

actv.io rails app

Activity Model

Local Proxy

DB

Activity Controller

Activity Clent Gem

Activity Service Gem

Host Ruby Application

Page 51: Taming monolithic monsters

actv.io rails app

Activity Model

API ProxyLocal Proxy

DB

API

REST

Activity Controller

Activity Clent Gem

Activity Service Gem

Host Ruby Application

Page 52: Taming monolithic monsters

demo - Rails App

Page 53: Taming monolithic monsters

actv.io rails app

Activity Model

API ProxyLocal Proxy

DB

API

REST

Activity Controller

Activity Clent Gem

Activity Service Gem

Host Ruby Application

Page 54: Taming monolithic monsters

No need for Rails, the API is the server application

API

Page 55: Taming monolithic monsters

No need for Rails, the API is the server application

Android App

API

Page 56: Taming monolithic monsters

No need for Rails, the API is the server application

Android App iOS App

API

Page 57: Taming monolithic monsters

No need for Rails, the API is the server application

Web App Android App iOS App

API

Page 58: Taming monolithic monsters

No need for Rails, the API is the server application

Web App Android App iOS App ... App

API

... App... App

Page 59: Taming monolithic monsters

api.restpack.org

Page 60: Taming monolithic monsters

Core

DB

api.restpack.org

Page 61: Taming monolithic monsters

DB DB

Core Users

api.restpack.org

Page 62: Taming monolithic monsters

DB DB DB

Core Users Groups

api.restpack.org

Page 63: Taming monolithic monsters

DB DB DB DB

Core Users Groups Account

api.restpack.org

Page 64: Taming monolithic monsters

DB DB DB DB DB

Core Users Groups Account Email

Redis

Job Q

api.restpack.org

Page 65: Taming monolithic monsters

DB DB DB DB DB

Core Users Groups Account Email

Redis

Job Q

api.restpack.orgApply Security Policy

Page 66: Taming monolithic monsters

DB DB DB DB DB

Core Users Groups Account Email

Redis

Job Q

api.restpack.org

dashboard.restpack.org

Apply Security Policy

Page 67: Taming monolithic monsters

DB DB DB DB DB

Core Users Groups Account Email

Redis

Job Q

api.restpack.org

dashboard.restpack.org

Apply Security Policy

3rd Party Applications3rd Party Applications

3rd Party Applications3rd Party Applications

Page 68: Taming monolithic monsters

demo - Ember.js App

Page 69: Taming monolithic monsters

Redis

Job Q

api.restpack.org

dashboard.restpack.org

DB

1 Application, 1 DB

Page 70: Taming monolithic monsters

DB DB DB DB DB

Core Users Groups Account Email

Redis

Job Q

api.restpack.org

dashboard.restpack.org

API

Apply Security Policy

API APIAPI API

Many Applications, Many DBs

Page 71: Taming monolithic monsters

@gavinjoycegithub.com/RestPack

Questions?