deploying node.js at scale - maraschi, collina - codemotion amsterdam 2016

81
Deploying Node.js at scale A developer journey @lucamaraschi @matteocollina

Upload: codemotion

Post on 16-Apr-2017

659 views

Category:

Technology


0 download

TRANSCRIPT

Page 2: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

DISCLAIMERNobody in this story, and no outfit or corporation, is based upon an actual person or outfit in the real world.The tale we are going to tell is completely fictional, but based upon the combined experiences of the speakers in building Node.js applications.

Page 3: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Meet bobHe is a .LAVA developer

He writes applications on the L2EE stack, using SQLobster as a database.

Page 4: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Bob reads:

Page 5: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Such speed

So enterprise

Wow JS

Page 6: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Bob decides:Let’s rewrite my HUGE application in node.js

Using the MEAN stack

Page 7: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

.js

Page 8: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

How do I deploy my Javascript monolith?

I read StackOverflow!

SSH into the virtual machine

● snowflake servers● git clone● forever!

No Integration tests, but 100% code coverage

Page 9: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

The new product has huge success

Bob is happy

Page 10: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

And the performance fall

Bob is SAAD

Page 11: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Such speed

So enterprise

Wow JS

Page 12: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

But my schema is relational...

One MongoDB collection for Student

One MongoDB collection for Email populate

Page 13: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

FactsMongoDB has no concept of relationship

We need relationships in our application

Let’s build a JOIN engine inside our application!

Taken from the Mongoose website

Page 14: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

FactsMongoDB has no concept of relationship

We need relationships in our application

Let’s build a JOIN engine inside our application!

Let’s do TWO queries to Mongo

If we used find() instead of findOne(), we would have done 1+N queries

Taken from the Mongoose website

Page 15: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

NoSQL is hard!

Relational vs. NoSQL

It is not Node fault!

Deduplication is accepted

Don’t shoot in your own foot

{ "name": "Matteo", "surname": "Collina", "phone": "+39 347123456", "emails": [{ "type": "university", "address": "[email protected]" }]}

Page 16: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

The fixed product has huge success

Bob is happyagain

Page 17: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

...but my servers stop responding!!!!

Page 18: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Such speed

So enterprise

Wow JS

Page 19: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Exhausted file descriptorsEvery incoming HTTP request is a file descriptor

Every outgoing HTTP request is a file descriptor

1. You receive an HTTP request call to /faulty2. In faulty, you call service A on /doSomething3. You pipe the result of /doSomething to the HTTP response4. An error happens, and you do not close the HTTP response

Fixed amount

Page 20: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Exhausted file descriptors: solution

Replace a.pipe(b)

With pump(a, b)

Page 21: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

We are back online!

Bob is happyagainagain

Page 22: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

● Scaling the development team from 1 (Bob) to 5

● Delivering more features in less time

● 1000 unit tests!● Serve more customers!

But the Business (always) wants more...

Page 23: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Such speed

So enterprise

Wow JS

Page 24: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

The new team does not deliver

Bob is SAAD

Page 25: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

MVC architectureReally monolithic

Adding a feature means changing all “layers” in an application

Does not scale with the team size

Equivalent VMs need to be dimensioned to handle the most demanding feature

Page 26: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Don’t push anything till tomorrow..

Page 27: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Developing with modules

Really monolithic

Adding a feature means changing all “layers” in an application

Does not scale with the team size up to a certain point

Equivalent VMs need to be dimensioned to handle the most demanding feature

Page 28: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Productivity goes up again!

Bob is happyagainagainagain

Page 29: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

● Scaling the development team from 5 to 20

● Delivering even more features in less time

● 10000 unit tests!● Serve more customers!

But the Business (always) wants more...

Page 30: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

The NEW new team does not deliverBob is DESPERATE

Page 31: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

===

Page 32: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

=== ++ distribution

Page 33: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Missing Resiliency

Fault tolerance

&&

Page 34: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

A pre-made “stack” might not be good

Page 35: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Let’s throw everything away...

But .LAVA42 does it better! ;-)

Page 36: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Hipsters use microservices

Page 37: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Such modularity

So enterprise

Wow micro

Very service

Page 38: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Microservices architecture

Really monolithic

Adding a feature means changing all “layers” in an application

Does not scale with the team size up to a certain point

Equivalent VMs need to be dimensioned to handle the most demanding feature

Page 39: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016
Page 40: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Queue in betweenHow we discover the queues?

How are the back channels / response handled?

Page 41: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

The answer to life

universe, and everything

Page 42: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

The answer to life

universe, and everything

The answer to everything is

service discovery

Page 43: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Discovery with DNS:Meet Consul

Page 44: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Etcd… but CoreOS

Page 45: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016
Page 46: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Scalable

Weakly consistent

Infection style

Membership protocol

Page 47: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

● Weakly consistent vs. strongly consistent

● Bornt for distributed systems

● Failure detection over the cluster

● Information dissemination

● Equally distribution of the workload

Advantages

Page 48: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Such consistency

So infectious

Wow failure detection

Very distributed

Page 49: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Common implementations

Hashicorp SERFIf you are into GO

mrhooray/swim-jsIf you are into JS ;-)

Page 50: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

But a new cluster node is added...

Page 51: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

How to rebalance the cluster topology?

Page 52: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016
Page 53: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Consistent hashring

Page 54: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

PROBLEM

How can I find a server over an unstable network?

SOLUTION

Each server and keys are hashed in a circular hashspace

Page 55: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016
Page 56: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Advantages

● Easier to avoid hotspots

● Enable partitioning● Predictable elasticity● Easy replication● Scalability and

Availability● Local state

Page 57: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

mcollina/upring

Page 58: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

What if Bob was working for Uber? ;-)

Page 59: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Application-level sharding

Page 60: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016
Page 61: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

The fourth secret of Fatima

Page 62: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

“Hyperbahn enables service discovery and routing for large-scale systems comprised of many microservices. Distributed, fault tolerant, and highly available, it lets one service find and communicate with others simply and reliably without

having to know where those services run.”

Page 63: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Featuring...

● Configuration Discovery

● Retries● Load Balancing● Rate Limiting● Circuit Breaking● Distributed tracing

Page 64: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

But what about HTTP?

Page 65: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016
Page 66: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

TChannel is a networking framing protocol used for general RPC, supporting out-of-order responses at extremely high performance where intermediaries can make a forwarding

decision quickly

Page 67: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Tracing as a first class resident...

https://github.com/openzipkin/zipkin

Page 68: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

WHY RPC?

Page 69: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Functions

Distributed

Clustered

Page 70: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016
Page 71: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Operation Complexity

Page 72: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

...but killsDEVELOPMENT

WORKFLOW

Page 73: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

“SERVERLESS”is the new Hipster

Page 74: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Such servers

So hipster

Wow functions

Very reactive

Page 75: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

“FUNCTIONAL”is the new Hipster

Page 76: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

“DISTRIBUTED FUNCTIONS”are the future!

Page 77: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Don’t be too late!

Page 78: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

@lucamaraschi

Page 79: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016
Page 81: Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016

Conclusions● Think about choosing a technology● Node.js works at scale● You can implement any architecture with Node.js