Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Microservices with Laravel Lumen

Mathias Hansen
November 18, 2015

Microservices with Laravel Lumen

PHP World 2015

Mathias Hansen

November 18, 2015
Tweet

More Decks by Mathias Hansen

Other Decks in Technology

Transcript

  1. Microservices with
    Laravel Lumen
    by @MathiasHansen
    php[world] 2015

    View Slide

  2. Who I Am
    » I speak English, Danish,
    and PHP
    » Have done so for most of
    my life
    » Self-proclaimed Laravel
    evangelist
    » Started Capital Laravel
    Group in 2013

    View Slide

  3. What I Do

    View Slide

  4. What We're
    Going to Do
    » Microservices, defined
    » How we're using
    Microservices at VB
    » Benefits and drawbacks
    » Microservices with Lumen
    » Questions

    View Slide

  5. What's a
    Microservice?

    View Slide

  6. A Microservice should be
    Designed around a
    single
    business capability

    View Slide

  7. View Slide

  8. View Slide

  9. We have...
    » A big monolithic app
    » A growing team
    » Concerns mostly separated
    » Let's go one step further

    View Slide

  10. ! Microservices !
    to the rescue

    View Slide

  11. View Slide

  12. Implementing a
    Microservice

    View Slide

  13. View Slide

  14. Define a contract
    » REST?
    » Protobuf?
    » SOAP? (please don't do this)

    View Slide

  15. Plan ahead
    » How big should your service be?
    » How many services should you have?
    » Share common code across services
    » use composer

    View Slide

  16. Use an API
    Manager
    » api.videoblocks.com/search
    ➡ searchservice.internal
    » api.videoblocks.com/abtest
    ➡ abtestservice.internal
    » Authentication
    » Rate limiting
    » Usage tracking

    View Slide

  17. A Microservice Hybrid or go all
    the way?
    » Monolithic app + Micro services
    » Static Frontend + Micro services
    » PHP Gateway + Micro services

    View Slide

  18. Immediate
    benefits

    View Slide

  19. Teamwork,
    simplified
    » Can use any programming
    language or data store
    under the hood
    » A small team can own the
    entire process from dev to
    deployments
    » Great for onboarding

    View Slide

  20. Deployments,
    simplified
    » Deploy a "piece" of the app
    instead of full monolith
    » Independent deployment
    schedule

    View Slide

  21. Testing,
    simplified
    » Unit test
    » Internal functionality
    » Integration test
    » External interface
    » Load test
    » Ability to test each
    service individually

    View Slide

  22. Scaling,
    simplified
    Allocate extra resources to
    the service that needs it
    » Isolate hot/cold zones

    View Slide

  23. Hold your horses

    View Slide

  24. View Slide

  25. Things to
    Consider

    View Slide

  26. Complexity
    » Increases complexity of
    your app
    » Network overhead
    » More planning necessary

    View Slide

  27. How big is your team?

    View Slide

  28. Automation is
    key
    Development ➡
    testing ➡
    deployment

    View Slide

  29. View Slide

  30. What is Lumen?

    View Slide

  31. A microframework
    » But not necessarily in the traditional sense
    » Based on Laravel components
    » Follows Laravel versioning
    » Laravel Lumen 5.1 ➡ Laravel 5.1

    View Slide

  32. It still packs a punch
    » Blade (templating)
    » Caching
    » Commands
    » Controllers
    » Eloquent ORM
    » Dependency Injection
    » Queueing
    » Testing
    » And more...

    View Slide

  33. If you're familiar
    with Laravel, you
    already know
    how to use Lumen.

    View Slide

  34. Lumen is fast

    View Slide

  35. No, seriously!
    It's kind of the point

    View Slide

  36. Faster routing
    +
    Opt-in rather than opt-out
    =
    Smaller footprint out of
    the box

    View Slide

  37. Routing
    » Uses nikic/FastRoute for
    routing
    » You don't need a fancy C
    extension to make routing
    fast

    View Slide

  38. Opt-in
    » Core features has to be explictly enabled:
    » dotenv, facades, Eloquent ORM, etc.
    » Service Providers
    » Middlewares
    » CSRF protection, cookie encryption, session
    handling etc.

    View Slide

  39. What is Lumen not?
    » Does not support Laravel 5 packages
    » Very minimal config system out of the box
    » Uses environment variables
    » Can use full config system if you want
    » Router has fewer features

    View Slide

  40. Use cases

    View Slide

  41. Use it for
    Microservices
    duh!

    View Slide

  42. Tiny websites
    Status page, landing page
    Example: status.geocod.io

    View Slide

  43. High-traffic component of your
    website
    Example: Envoyer cron job heartbeat

    View Slide

  44. The competition

    View Slide

  45. Conclusion
    » Define your contract first
    » Design your microservice around a single business
    capability
    » Plan ahead
    » Define testing & deployment strategy
    » Use Lumen for microservices or other small
    standalone apps

    View Slide

  46. Additional resources
    Building Microservices
    by Sam Newman
    Martin Fowler's Articles
    http://martinfowler.com/articles/microservices.html
    Taylor Otwell's Lumen Laracasts
    https://laracasts.com/lessons/introducing-lumen

    View Slide

  47. Questions?
    Talk to me
    @MathiasHansen
    [email protected]

    View Slide