1 of 50

Web Architecture

& Ruby

https://bit.ly/arch-lrug

​

equivalent@eq8.eu

www.eq8.eu

equivalent8

equivalent

​

​

​

​

​

​

​

​

2 of 50

Talk Outline

  • Architecture approaches
    • Monolith
    • Microservices
    • Serverless
  • Hybrid solutions

3 of 50

From perspective of AWS

  • Just because I have the most experiences with this provider
  • There are many other providers that support similar thing

4 of 50

Online Store (Responsibilities)

Product list

​

Basket

​

Orders

​

Payment gateway

​

Admin

​

​

Auth

5 of 50

Monolith means many things

  • Mighty monolith (Rails, DHH)
  • BE / FE split
  • Event loop? Puma ? Unicorn ? Functional prog. monolith ? (e.g.: Elixir)

​

6 of 50

Monolith - Codebase

  • One codebase
    • E.g.: Rails
  • Communication of responsibilities on a code level
  • Admin for multiple responsibilities within the same codebase
  • Auth for entire codebase

​

​

7 of 50

Monolith Server

  • Entire codebase deployed to a VM / Heroku Dyno
  • To deploy one responsibility you need to deploy entire app

​

​

​

​

8 of 50

Monolith - Con.

​

​

​

  • Entire codebase has access to all connections

​

​

​

​

9 of 50

Monolith - Scale

  • To scale one responsibility, you need to scale all

​

​

10 of 50

Microservices

In short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.��-- James Lewis and Martin Fowler

https://martinfowler.com/microservices/#what�

11 of 50

Microservices

  • Multiple codebases
  • Deploy individual responsibility
  • Every service has their own datastore
  • Scale individual responsibility

​

​

12 of 50

Classic LB

  • Scaling classic load balancer
  • AWS ELB

​

​

13 of 50

Scaling ALB

  • Application load balancer
  • AWS ALB

​

​

14 of 50

Communication

  • Services talk to each other via common public interface (e.g.: JSON)

​

15 of 50

Authentication

  • Oauth
  • JWT

​

16 of 50

17 of 50

JWT

https://bit.ly/arch-lrug

18 of 50

How much code should be inside MicroService?

Option A:

​

Just enough to execute one task

​

Option B:

​

Enough so that microservice

is self-governed

19 of 50

How much code should be inside MicroService?

Option A:

​

Just enough to execute one task

​

Option B:

​

Enough so that microservice

is self-governed

20 of 50

Where is admin?

21 of 50

“God” MicroService ?

  • In OOP we try to avoid “God” objects
  • In MicroServices we try to avoid “God” Service

​

22 of 50

“God” MicroService ?

  • In OOP we try to avoid “God” objects
  • In MicroServices we try to avoid “God” Service

​

23 of 50

Service related Admin

  • Service takes care of the entire responsibility

​

24 of 50

Like cells in your body

25 of 50

Super Cool

Source: Mastering Chaos - A Netflix Guide to Microservices by Josh Evans https://goo.gl/EmPXiG

26 of 50

Conway’s Law

Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization's communication structure.

27 of 50

Organization

  • Team is responsible for entire lifecycle of the service
  • Responsible for development (FE, BE), deployment and support

​

28 of 50

Two-Pizza Team

  • 2 pizzas should be enough to feed the entire team
  • Amazon (Jeff Bezos)
  • Small team behind microservice

​

​

​

29 of 50

Too Big ?

​

​

30 of 50

Split !

​

​

31 of 50

Why is not everyone doing it ?

32 of 50

Microservices - cost

Every service needs:

  • Own VM
  • Own DB

​

Employee cost:

  • Develop own API
  • Know how to consume other API
  • Devops setup

​

33 of 50

Multiple environments

Production

Staging

QA

34 of 50

Reasonable solutions exist

With containers you can run multiple services on one VM

35 of 50

Microservices

In short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.��-- James Lewis and Martin Fowler

https://martinfowler.com/microservices/#what��

36 of 50

Serverless

37 of 50

AWS Lambda

  • Code + dependencies zipped -> AWS Lambda
  • Lambda gets invoked
  • Pay for execution time + memory usage

38 of 50

AWS Lambda

What AWS S3 is to storage, AWS Lambda is to compute

39 of 50

It’s called FaaS

  • Function-as-a-Service
    • AWS Lambda
    • Microsoft Azure Functions
    • IBM Cloud Functions (Apache OpenWhisk)
    • Iron.io
    • Webtask.io
    • ...and more are coming

​

​

​

40 of 50

Serverless

41 of 50

Our App

  • Serverless is just a different way how to do microservices

​

42 of 50

How much code should be inside Serverless?

Option A:

​

Just enough to execute one task

​

Option B:

​

Enough so that microservice

is self-governed

43 of 50

Serverless

  • No, you cannot put entire Rails app to one Lambda Function !
    • On second thought, yes you can run small app Web Server on Lambda (Express JS)
    • 1:1 Mapping -> 1 request runs on 1 Lamba
    • To ease the migration pain
  • Business logic to Library
  • Check out Serverless Framework https://serverless.com/

​

44 of 50

No Ruby :(

  • JavaScript, Python, Java, … No Ruby
  • Ruby is coming !

​

45 of 50

Please help to request Ruby FaaS

https://www.serverless-ruby.org

​

https://bit.ly/arch-lrug

46 of 50

Serverless Ruby ?

  • Traveling Ruby
    • JS/Py Lambda to trigger binary executable of Ruby
  • JRuby on Java Lambda

​

​

https://bit.ly/arch-lrug

47 of 50

Monolith is not Dead !

48 of 50

Hybrid solutions

49 of 50

Bounded contexts in Monolith

  • e.g.: Rails Engine
    • rails plugin new product_listing --mountable
    • rails plugin new basket --mountable
    • rails plugin new orders --mountable
    • rails plugin new payment --mountable

​

  • Latest version of Phoenix framework (Elixir lang.) supports Bounded contexts out of the box

​

​

​

​

50 of 50

Web Architecture

& Ruby

https://bit.ly/arch-lrug

​

equivalent@eq8.eu

www.eq8.eu

equivalent8

equivalent

​

​

​

​

​

​

​

​