vilius lukošius - decomposing distributed monolith with node.js (wix.com)

66
Decomposing distributed monolith with Node.js Vilius, Software Engineer linkedin/viliusl github.com/viliusl @viliusl [email protected]

Upload: agile-lietuva

Post on 23-Jan-2018

26 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Decomposing

distributed monolith with

Node.jsVilius, Software Engineer

linkedin/viliusl github.com/viliusl@[email protected]

Page 2: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Decomposing

distributed monolith with

Node.jsVilius, Sofware Engineer

linkedin/viliusl github.com/viliusl@[email protected]

Stack of your

choice

Page 3: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Hi. I am Vilius

Lithuania

Ukraine

Vilnius

Kyiv

Dnipro

Wix Engineering Locations

Israel

Tel-Aviv

Be’er Sheva

Page 4: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Hi. I am Vilius

Lithuania

Vilnius

Wix Engineering Locations

Page 5: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

AGENDA

Microservices and Distributed Monolith

(DM)

Why am I talking about DM in first place?

Short history and joys of adding 2nd stack

Decomposing Distributed Monolith

Page 6: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

“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”

Martin Fowler

Page 7: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

What is a

distributed

monolith

01

Page 8: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

A form of a binary coupling, when in

order to interact and coexist in a

given system you are required to

use a set of “official” libraries.

Page 9: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Client library becomes “Only” official

way to access the service

Page 10: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

What’s wrong with it?

Page 11: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Nearly impossible to adopt new

architectures, languages, etc.

Page 12: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

But hey, DRY, code reuse - it’s good

right?

Page 13: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

“The evils of too much coupling

between services are far worse than

the problems caused by code

duplication”

Sam Newman, Building

Microservices

Page 14: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

You potentially lose

polyglot;

organizational/technical decoupling;

temporal decoupling;

Page 15: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Ok, so what is an alternative?

Page 16: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Contracts and protocols!

Page 17: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Yeah, but central logging, distributed

tracing, context passing….

Page 18: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

You don’t need binary coupling

Standardization via protocols and contracts and independent libraries

Compliancy/contract tests

Page 19: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Why am I talking about

Distributed Monolith in the first

place?

02

Page 20: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Let’s answer to 2 following questions

honestly

Page 21: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Does it take months to upgrade a

library across company?

Page 22: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Does it take months to upgrade a

library across company?

Page 23: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Does it take ~ a year to introduce a

new stack?

Page 24: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Introducing a Node.js stack @

Wix

03

Page 25: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

“Target or this project is to enable

coding front-end servers in Wix using

Node.js. We are aiming at the

pattern of front-end servers and

service-servers – a pattern that is

used in different companies”

Yoav Abrahami

Page 26: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Page 27: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Page 28: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Page 29: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Does not look too hard right?

Page 30: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Page 31: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Page 32: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

But wait, there is more…

Page 33: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Page 34: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Page 35: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Oh, and ops contracts…

Page 36: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Page 37: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

But not all is gloom and doom

Page 38: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Build/Deploy pipeline* already had

support/extensions for non-official

stack

*lifecycle, fryingpan, teamcity

Page 39: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Contract for deploying application

was defined, sane, simple*

*https://kb.wixpress.com/display/system/Docker+image+deployment+requirement

Page 40: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Contract for configuration was clear

and defined*

* https://kb.wixpress.com/display/chef/Wix+Artifact+Config+Templates

Page 41: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Underlying protocols were

standardized, business services as

proper microservices

Page 42: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Decomposing Distributed

Monolith

04

Page 43: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

There were never a goal to

decompose, fix, re-architect existing

stack

Page 44: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

The goal was to introduce new one

to be leaner, be faster, make us go

faster

Page 45: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Decomposition is just a side-effect if

you want to actually be leaner, go

faster

Page 46: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Step #1 – just do it!

Page 47: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

// todo - talk to Vilius about that

var url = req => req.protocol + '://' + req.get('host') + req.originalUrl;

// todo - add petri enricher

return new WixRpcClientSupport(

reqContext.get(wixRequestContext),

rpcSigner.get(options.rpcSigningKey),

wixSessionEnricher.get(wixSession),

biEnricher.get(wixBi)

);

module.exports.addTo = app => {

app.get('/health/is_alive', (req, res) => res.send('Alive'));

};

Some TODOs

Page 48: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Proxy APIs for fat clients

Page 49: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Cover bare-minimum to run in

production

Page 50: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Step #2 – we got noticed!

Page 51: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Page 52: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

const {expect} = require('chai'),

testkit = require('./support/testkit'),

http = require('wnp-http-test-client'),

jvmTestkit = require('wix-jvm-bootstrap-testkit');

describe('petri client', function () {

const app = testkit.server('petri').beforeAndAfter();

const jvmTestkit = jvmTestkit.server({

artifact: {

groupId: 'com.wixpress.node',

artifactId: 'wix-spjs-test-server'

}

}).beforeAndAfter();

it('should conduct AB test', () =>

givenABTest('scope', 'anExperiment')

.then(() => conductExperiment('anExperiment'))

.then(res => expect(res).to.equal('true'))

);

//...

});

Test-kits based off

of a core platform

RPC

Petri

Session

Page 53: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Step #3 – time to get serious –

compliancy tests are born.

Page 54: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Platform agnostic

Page 55: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

trait HealthProtocol extends BaseHealthSpec with HealthDriverSupport {

"health monitoring - protocol" >> {

"/health/is_alive responds with failure" >> {

healthTestDependency.becomeUnavailable()

eventually {

queryIsAliveAPI must beUnavailable

}

}

"/health/is_alive responds with success" >> {

healthTestDependency.becomeAvailable()

eventually {

queryIsAliveAPI must beSuccessfulWith("Alive")

}

}

"health tests executed with three retries" >> {

stabilizeInHealthyState()

healthTestDependency.becomeFlaky(consecutiveFailures = 1)

holds(samples = 100, sleep = 50.milliseconds) {

queryIsAliveAPI must beSuccessful

}

}

Generic tests

Using testkits;

Platform-agnostic.

Page 56: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

class NodeComplianceE2E extends BaseComplianceE2E

with HealthAll

with SecurityAll

with I18nAll

with PetriAll

with BiAll

with WebAll

with NodeMetricKeys

with NodeBiKeys

with RpcAll {

LogbackTestHelper.initLogger()

override protected def systemUnderTest: MainService =

new LocalNodeService

}

Easy to add another

stack

App with exposed

APIs

Adapters

Runner

Page 57: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

What is a contract and what is not?

Page 58: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Isn’t it like… monolithic?

Page 59: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)
Page 60: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

We are at the junction

Page 61: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Proxy

Page 62: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

API’s and compliance

Page 63: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

So that we could pass a Litmus test

Page 64: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

“can I actually take a team of

engineers who are interested in X

becoming a legit thing in my service

and actually build something without

convincing the rest of the company?”

Ben Christensen,

Facebook

Page 65: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Thank You

linkedin/viliusl github.com/viliusl@[email protected]

Page 66: Vilius Lukošius - Decomposing distributed monolith with Node.js (WIX.com)

Q&A

linkedin/viliusl github.com/viliusl@[email protected]