$30 off During Our Annual Pro Sale. View Details »

Microservices késako

Boris Feld
October 17, 2015

Microservices késako

What is a microservices? A tale of computer company. A presentation of micro-services and how to create them with ZeroServices, a python micro-services framework.

Boris Feld

October 17, 2015
Tweet

More Decks by Boris Feld

Other Decks in Programming

Transcript

  1. MICROSERVICE KÉSAKO
    BORIS FELD - PYCONFR 2015

    View Slide

  2. Once upon a time
    A computer tale

    View Slide

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

    View Slide

  4. In a little company…

    View Slide

  5. A developer

    View Slide

  6. A tester

    View Slide

  7. A DevOps

    View Slide

  8. A product owner

    View Slide

  9. Worked together in harmony

    View Slide

  10. Little project grew up

    View Slide

  11. And each change became more urgent than the
    precedent

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  15. Conflicts emerged

    View Slide

  16. Resulting in a mess

    View Slide

  17. As the fear grew, the release rhythm slowed down

    View Slide

  18. Which only made the fear of change grew stronger

    View Slide

  19. We’re all humans

    View Slide

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

    View Slide

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

    View Slide

  22. FROM MONOLITH…

    View Slide

  23. TO MICROSERVICES

    View Slide

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

    View Slide

  25. EXAMPLE
    User management service

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  29. ISOLATION
    Communicate over

    Network
    No data leak through
    layers

    View Slide

  30. SCALING
    Easier to scale IF STATELESS

    View Slide

  31. BEST LANGUAGE
    Choose the best tool And change it later

    View Slide

  32. BEST DATASTORE
    Polyglot persistence Easier to change

    View Slide

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

    View Slide

  34. DESIGN
    Communication

    View Slide

  35. DISCOVERY
    Discovery
    Communication

    View Slide

  36. DATA-BACKEND
    Discovery
    Data-backend Communication

    View Slide

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

    View Slide

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

    View Slide

  39. 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

    View Slide

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

    View Slide

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

    View Slide

  42. 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()

    View Slide

  43. 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()

    View Slide

  44. DEMO TIME!

    View Slide

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

    View Slide

  46. 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()

    View Slide

  47. RESULT

    View Slide

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

    View Slide

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

    View Slide