Slide 1

Slide 1 text

MICROSERVICE KÉSAKO BORIS FELD - PYCONFR 2015

Slide 2

Slide 2 text

Once upon a time A computer tale

Slide 3

Slide 3 text

- Disclaimer « Any resemblance to actual events, to persons living or dead, is not the result of chance. It is DELIBERATE »

Slide 4

Slide 4 text

In a little company…

Slide 5

Slide 5 text

A developer

Slide 6

Slide 6 text

A tester

Slide 7

Slide 7 text

A DevOps

Slide 8

Slide 8 text

A product owner

Slide 9

Slide 9 text

Worked together in harmony

Slide 10

Slide 10 text

Little project grew up

Slide 11

Slide 11 text

And each change became more urgent than the precedent

Slide 12

Slide 12 text

If I have to change anything on this project I will kill myself

Slide 13

Slide 13 text

If I have to play the whole test suite once again, I’m good for another therapy

Slide 14

Slide 14 text

If I have to deploy this project and maintain it, I will be able to buy a new car with the on-cull duty

Slide 15

Slide 15 text

Conflicts emerged

Slide 16

Slide 16 text

Resulting in a mess

Slide 17

Slide 17 text

As the fear grew, the release rhythm slowed down

Slide 18

Slide 18 text

Which only made the fear of change grew stronger

Slide 19

Slide 19 text

We’re all humans

Slide 20

Slide 20 text

-Tony Robbins « By changing nothing, nothing changes. »

Slide 21

Slide 21 text

WHY? • Monolith • Hard to change • Inertia for refactoring / improvement • « Container carrier » size

Slide 22

Slide 22 text

FROM MONOLITH…

Slide 23

Slide 23 text

TO MICROSERVICES

Slide 24

Slide 24 text

MICROSERVICES • Small isolated cooperative units • Aim to reduce: • FEAR OF CHANGE • Complexity • Inertia

Slide 25

Slide 25 text

EXAMPLE User management service

Slide 26

Slide 26 text

SMALL Simple composant Easy to understand Easy to maintain Fit in the head

Slide 27

Slide 27 text

SINGLE RESPONSIBILITY Do one thing Do it well Single source of truth Unix way

Slide 28

Slide 28 text

BLACK-BOX Expose a contract What it does What it returns And the format

Slide 29

Slide 29 text

ISOLATION Communicate over
 Network No data leak through layers

Slide 30

Slide 30 text

SCALING Easier to scale IF STATELESS

Slide 31

Slide 31 text

BEST LANGUAGE Choose the best tool And change it later

Slide 32

Slide 32 text

BEST DATASTORE Polyglot persistence Easier to change

Slide 33

Slide 33 text

MORE DETAILED PRESENTATION ABOUT MICRO SERVICES • https://speakerdeck.com/lothiraldan/ microservices-introduction

Slide 34

Slide 34 text

DESIGN Communication

Slide 35

Slide 35 text

DISCOVERY Discovery Communication

Slide 36

Slide 36 text

DATA-BACKEND Discovery Data-backend Communication

Slide 37

Slide 37 text

INTERFACES HTTP Interface Websocket Interface Other interface Discovery Data-backend Communication

Slide 38

Slide 38 text

INTERFACES µService HTTP Interface Websocket Interface Other interface Discovery Data-backend Communication

Slide 39

Slide 39 text

ZEROSERVICES • A framework for all theses bricks • And a reference implementation for all of them • Python 3.4 • Asynchronous / Asyncio • Changes are broadcasted as events

Slide 40

Slide 40 text

RESOURCE-ORIENTED • REST without HTTP • One and unique way to do CRUD operation • Valuable when combined with broadcasted changes

Slide 41

Slide 41 text

REST API • Bind your endpoints to your code • What about websocket API? • Or IRC?

Slide 42

Slide 42 text

WHAT IT LOOKS LIKE? RESOURCE SERVICE loop = asyncio.get_event_loop() medium = ZeroMQMedium(loop, UdpDiscoveryMedium) service = ResourceService('power_service', medium) service.register_resource(MongoDBCollection("power", "db")) loop.run_until_complete(todo.start()) loop.run_forever()

Slide 43

Slide 43 text

REAL-TIME REST API loop = asyncio.get_event_loop() medium = ZeroMQMedium(loop, UdpDiscoveryMedium) service = ResourceService('rest_api', medium) application = get_http_interface(service, loop, port=5001, allowed_origins="*") application = loop.run_until_complete(application) loop.run_until_complete(service.start()) loop.run_forever()

Slide 44

Slide 44 text

DEMO TIME!

Slide 45

Slide 45 text

PROBLEMS WITH MICRO- SERVICES • Micro-service needs to know where are the others. • Made testing difficult. • Framework should abstract that. • Start without DevOps burdens.

Slide 46

Slide 46 text

COMBINED loop = asyncio.get_event_loop() medium = ZeroMQMedium(loop, UdpDiscoveryMedium) service = ResourceService('power_service', medium) service.register_resource(MongoDBCollection("power", "db")) application = get_http_interface(service, loop, port=5001, allowed_origins="*") application = loop.run_until_complete(application) loop.run_until_complete(todo.start()) loop.run_forever()

Slide 47

Slide 47 text

RESULT

Slide 48

Slide 48 text

EXPOSED VIA WEBSOCKET • Changes exposed via real-time endpoint (websocket, etc…) • Easy to consume as REST-oriented • Works great with React / Flux

Slide 49

Slide 49 text

CONCLUSION • Give it a try! • https://github.com/Lothiraldan/ZeroServices • Let’s sprint on it!