microservices monoliths - the php · hhvm: jit compiler for php — adam bien, "enterprise...

80
Of Microservices And Monoliths Stefan Priebsch, The PHP Consulting Company

Upload: others

Post on 18-Oct-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Of  Microservices  And  Monoliths

Stefan Priebsch, The PHP Consulting Company

Page 2: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?
Page 3: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Consultant

Page 4: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Consultant

Coach

Page 5: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Consultant

Coach

Author

Page 6: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Consultant

Coach

Author

University Lecturer

Page 7: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Consultant

Coach

Author

University Lecturer

Scalability Expert

Page 8: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?
Page 9: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?
Page 10: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Working on "Event Sourcing Explained"

Visit https://event-sourcing-explained.com/

Page 11: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Monolith = Antipattern?

Page 12: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

In most cases, monoliths are the status quo.

Page 13: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

The Distributed Monolith

Page 14: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

The Distributed Monolith

Does a change to one microservice require changes to or deployments of other microservices?

Are your microservices overly chatty?

Do several microservices share a datastore?

Do my services scale dynamically?

https://blog.newrelic.com/engineering/distributed-monolith-vs-microservices/

Page 15: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

The Distributed Monolith

Implementing one business feature requires touching multiple microservices

Page 16: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?
Page 17: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

~ 30 Mio lines of PHP code

Page 18: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Interesting performance problems

Page 19: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

HipHop: Cross-compile PHP to C++

Page 20: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

50% less CPU

Page 21: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

1.5 GB binaries

Page 22: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Deployment?

Page 23: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Local testing?

Page 24: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Compiler in production, interpreter in development

Page 25: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

HHVM: JIT compiler for PHP

Page 26: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

— Adam Bien, "Enterprise Architekturen"

⟫ ⟪Every architecture's number one enemy is the compiler.

Page 27: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Compile into monolith?

Page 28: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Single process vs. network latency

Page 29: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Deployment?

Page 30: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Scripting languages

Page 31: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Deploy source code into production

Page 32: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Load code dynamically

Page 33: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Request/Response

Page 34: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Static object graph

Page 35: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Short lifetime

Page 36: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

External state

Page 37: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Serverless?

Page 38: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Boundaries

Page 39: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Boundaries

Decomposition

Page 40: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Boundaries

Decomposition

Coupling

Page 41: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Tight coupling starts in the business

Page 42: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Quote

Order

Invoice

Page 43: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Order::fromQuote(...)

Invoice::fromOrder(...)

Page 44: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Decouple

Page 45: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Abstract

Page 46: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?
Page 47: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?
Page 48: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

...

$twitter= new TwitterAPIExchange($settings);

...

$twitter->buildOauth($url, $requestMethod) ->setPostfields($postfields) ->performRequest();

Page 49: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Still very technical!

Page 50: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Domain view?

Page 51: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

$twitter->tweet(...);

Page 52: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

$microblog->publishMessage(...);

Page 53: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

"Abstractions should not depend upon details"

Page 54: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

$remoteService->authenticate($credentials);$remoteService->sendRequest(...);

Page 55: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

...

public function publish($message){ $this->microblog->authenticate(...); $this->microblog->sendRequest(...);}

...

Page 56: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

— John V. Guttag

The essence of abstractions is preserving information that isrelevant in a given context, and forgetting information that is

irrelevant in that context.

Page 57: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Details:

API requires authentication

Resources have URLs

...

Page 58: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

REST is an implementation detail

of the client-server communication

Page 59: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Why REST?

Page 60: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

public function publishMessage($message){ ... $this->authenticate(...); $this->sendPostRequest(...); ...}

Page 61: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

public function publishMessage($message){ ... $this->sendJsonRpc(...); ...}

Page 62: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

public function publishMessage($message){ ... $this->sendXmlRpc(...); ...}

Page 63: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

public function publishMessage($message){ ... $this->sendSoapRequest(...); ...}

Page 64: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Integrate client and server in one process?

Page 65: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Develop distributed, deploy monolithic

Page 66: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Facade API

Page 67: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

The API is an interface (as in class implements interface)

Page 68: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Facade API

Tell to do something

Ask a question

Page 69: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Facade API

Send a command (e.g. "publish message")

Run a query (e.g. "show list of friends")

Page 70: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

CQRS

Page 71: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

CQRS

Use a REST API for queries

Use an RPC-style API for commands

Page 72: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Separate side e�ects

Page 73: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Separate side e�ects

Record the decision to publish a message. Deal with the side e�ects later.

Page 74: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Need-to-know principle

Page 75: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Push Model

Page 76: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

More async, less sync

No temporal coupling

Page 77: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Vertical vs. horizontal separation

Page 78: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Self-contained systems

Page 79: Microservices Monoliths - The PHP · HHVM: JIT compiler for PHP — Adam Bien, "Enterprise Architekturen" Every architecture's number one enemy is the compiler. Compile into monolith?

Self-contained systems

Each SCS is an autonomous web application.

Each SCS is owned by one team.

Communication with other SCSs or 3rd party systems is asynchronous wherever possible.

An SCS can have an optional service API.

Each SCS must include data and logic.

An SCS should make its features usable to end-users by its own UI.

To avoid tight coupling an SCS should share no business code with other SCSs.

Shared infrastructure should be reduced to increase availability and decrease coupling.