PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome...

119
ROME 27-28 march 2015 Alessandro Cinelli (cirpo) PHP is the king, nodejs is the prince, Python the fool

Transcript of PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome...

Page 1: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

ROME 27-28 march 2015

Alessandro Cinelli (cirpo)

PHP is the king, nodejs is the prince, Python the fool

Page 2: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

ROME 27-28 march 2015

Alessandro Cinelli (cirpo)

Page 3: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 4: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

dubai

Page 5: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

dubai

Page 6: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

namshi

Page 7: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

namshinamshi

Page 8: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

Namshi

almost 3 years old

~350 ppl

IT team ~15 ppl

million+ visits per month

serving the UAE and GCC

Page 9: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 10: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 11: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 12: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 13: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 14: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 15: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 16: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

ARCHITECTURE

Page 17: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

a monolithic architecture

Page 18: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

so far so good… but we started growing…

Page 19: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

“we need a brand new feature for the warehouse…”

Page 20: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

SOA

Page 21: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

Service Oriented Architecture

Page 22: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

“A software design based on discrete software components, "services", that collectively

provide the functionalities of the larger software application”

– A.Nadalin (@_odino_)

Page 23: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

“Microservice Architecture" […] a particular way of designing software applications as suites of

independently deployable services…”

– M.Fowler

FULL STACK IS DEAD!

Page 24: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

services as LEGO bricks

Page 25: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

UNIX Philosophy

“Write programs that do one thing and do it well.”

Page 26: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

SOA BENEFITS

Page 27: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

SOA BENEFITS

scalability

Page 28: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

SOA BENEFITS

scalability avoid single point of failure

Page 29: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

SOA BENEFITS

scalability avoid single point of failure easier and faster deploys

Page 30: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

SOA BENEFITS

scalability avoid single point of failure easier and faster deploys isolation

Page 31: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

SOA BENEFITS

scalability avoid single point of failure easier and faster deploys isolation maintainability

Page 32: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

SOA BENEFITS

scalability avoid single point of failure easier and faster deploys isolation maintainability easier to replace existing parts

Page 33: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

How do you connect services?

Page 34: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

HTTP

A protocol that is almost 25 years old and is here to stay!

Page 35: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

GET vs POST

Page 36: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

GET vs POST“The difference is that in

a GET request you have the parameters in the url ,

with

a POST the parameters are in the request’s body”

answered by 80% of candidates during the interview

Page 37: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 38: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

“you don’t know HTTP? you shall not pass”

- Gandalf

Page 39: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

RabbitMq

Page 40: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

using crons!

Page 41: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

RabbitMq

publish consume

q u e u e

Page 42: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

RabbitMq

github.com/videlalvaro/php-amqplib

Page 43: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

RabbitMq

github.com/videlalvaro/php-amqplib

Page 44: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

RabbitMq

Language and protocol format agnostic

Page 45: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

RabbitMq

Language and protocol format agnostic You can easily create an event driven architecture

Page 46: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

RabbitMq

Language and protocol format agnostic You can easily create an event driven architecture Messages stay in the queue if a service goes down

Page 47: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

RabbitMq

Language and protocol format agnostic You can easily create an event driven architecture Messages stay in the queue if a service goes down Too many messages? add more consumers!

Page 48: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHP

Page 49: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHPIt follows standards (PSR-*)

Page 50: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHPIt follows standards (PSR-*)

Decoupled components

Page 51: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHPIt follows standards (PSR-*)

Decoupled components

Huge and active opensource community

Page 52: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHPIt follows standards (PSR-*)

Decoupled components

Huge and active opensource community

Easy to plug in your domain code

Page 53: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHPIt follows standards (PSR-*)

Decoupled components

Huge and active opensource community

Easy to plug in your domain code

Not just a framework, but a project…

Page 54: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHPIt follows standards (PSR-*)

Decoupled components

Huge and active opensource community

Easy to plug in your domain code

Not just a framework, but a project…

Designed starting from the HTTP protocol

Page 55: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHP

bundle -> app -> service

Page 56: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHP

UserBundle

WarehouseBundle

CheckoutBundle

ProductBundle

[…]

Page 57: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

Once you have a SOLID set of api foundation you can easily start building other awesome applications

Page 58: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHP - Silex

the PHP micro-framework based on Symfony2 Components

Page 59: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHP - Silex

Page 60: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

Let’s eat those apis!

Page 61: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

Javascript

Page 62: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JavascriptTwo way data-binding Single page application Built-in services on top of XHR Routing Controller Model

Page 63: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JavascriptTwo way data-binding Single page application Built-in services on top of XHR Routing Controller Model

it’s a MVW framework: Model-View-Whatever

Page 64: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

Javascript

Page 65: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

Javascript

Page 66: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

Javascript

Page 67: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

Javascript

Page 68: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

party time!

Page 69: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

FROM STATEFUL TO STATELESS

Removed server sessions Sessions on the client (localstorage)

Page 70: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

STATELESS

JSON Web Signaturehttp://tools.ietf.org/html/draft-jones-json-web-signature-04

Page 71: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHP -JWS

github.com/namshi/jose

JOSÉ

Page 72: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHP -JWS

Page 73: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PHP -JWS

Page 74: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

double party time!

Page 75: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

let’s do the same with the desktop website!

Page 76: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

some customers were experiencing some issues…

Page 77: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JAVASCRIPT

Page 78: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JAVASCRIPT

Page 79: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JAVASCRIPT

Page 80: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

we rebuilt the desktop website in two weeks!

Page 81: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JAVASCRIPT

Rapid application development Quick setup Event driven Javascript!

why node?

Page 82: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

github.com/namshi/mockserver

mockserver mock your APIs in a matter of seconds!

JAVASCRIPT

Page 83: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JAVASCRIPT

Page 84: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JAVASCRIPT

mockserver

Page 85: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JAVASCRIPTusers_GET.mock file

mockserver

Page 86: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JAVASCRIPT

mockserver

Page 87: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JAVASCRIPT

github.com/namshi/shisha

shisha smoke tests made easy!

Page 88: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JAVASCRIPT

shisha

.smoke file

Page 89: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

JAVASCRIPT

shisha

Page 90: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

REDIS

Page 91: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

REDISKey types: lists, hashes, sets, sorted sets

Page 92: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

REDISKey types: lists, hashes, sets, sorted sets Persistent to disk

Page 93: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

REDISKey types: lists, hashes, sets, sorted sets Persistent to disk Up to 512MB per key

Page 94: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

REDISKey types: lists, hashes, sets, sorted sets Persistent to disk Up to 512MB per key Pub/sub

Page 95: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

REDISKey types: lists, hashes, sets, sorted sets Persistent to disk Up to 512MB per key Pub/sub Transactions with optimistic locking

Page 96: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

REDIS

github.com/nrk/predis

Page 97: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PYTHON

Page 98: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

PYTHONData analysis

Small app with flask

Sys scripts

Page 99: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

DOCKER

Page 100: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

“Operating-system-level virtualization is a virtualization method where the kernel of an

operating system allows for multiple isolated user space instances, instead of just one.

Such instances, often called CONTAINERS, or jails, may look and feel like a real server from

the point of view of its owners and users.”

http://en.wikipedia.org/wiki/Docker_%28software%29

Page 101: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 102: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

lego

Page 103: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 104: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 105: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 106: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015
Page 107: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

ONE CONTAINER =

ONE COMMAND

Page 108: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

DIFFERENCE BETWEEN A VM AND DOCKER

HOST OS

GUEST OS

HYPERVISOR

BIN/ LIBS

APP A

APP CAPP B

GUEST OS

BIN/ LIBS

APP Z

APP HAPP B

GUEST OS

BIN/ LIBS

APP A

APP DAPP L

HOST OSDOCKER ENGINE

BIN/ LIBS

APP ABIN/ LIBS

APP ZBIN/ LIBS

APP DBIN/ LIBS

APP B{ {

VM

Page 109: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

CURRENT ARCHITECTURE

other clients

Page 110: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

WHAT’S NEXT?

(more)

(maybe)

Page 111: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

il mondo è bello perché è vario

The world is beautiful because it is varied

il mondo è bello perché è vario

Page 112: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

il mondo è bello perché è vario

The world is beautiful because it is varied

open your mind…

Page 113: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

use the right tool

Page 114: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

you can solve problems in different ways

Page 115: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

@cirpo

github.com/cirpo

/

Page 116: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

thanks

Page 117: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

tech.namshi.com/join-us

tech.namshi.com

github.com/namshi

@TechNamshi we are hiring!

Page 118: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

thanks

Page 119: PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cinelli - Codemotion Rome 2015

https://farm3.staticflickr.com/2199/2365883747_3a5c753719_o.jpg https://www.flickr.com/photos/karen_roe/8912245799

https://www.flickr.com/photos/anaxila/367953499/sizes/l https://www.flickr.com/photos/onigiri_chang/5356325784/sizes/o/

http://www.slideshare.net/odino/soa-with-symfony2-confoo-2014-in-montreal-ca https://www.flickr.com/photos/ejpphoto/2314610838/sizes/o/

https://www.flickr.com/photos/cesarastudillo/3981364314/sizes/l https://www.flickr.com/photos/piers_nye/2501994750/sizes/o/

https://www.flickr.com/photos/36247316@N00/3108399560/sizes/o/ https://www.flickr.com/photos/ironpoison_photos_69/9604127837/sizes/k/

https://www.flickr.com/photos/chrisschoenbohm/5104367911/sizes/l

credits