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 full-size 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 full-size slide

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

    View full-size slide

  4. What's a
    Microservice?

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  7. ! Microservices !
    to the rescue

    View full-size slide

  8. Implementing a
    Microservice

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  13. Immediate
    benefits

    View full-size slide

  14. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  18. Hold your horses

    View full-size slide

  19. Things to
    Consider

    View full-size slide

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

    View full-size slide

  21. How big is your team?

    View full-size slide

  22. Automation is
    key
    Development ➡
    testing ➡
    deployment

    View full-size slide

  23. What is Lumen?

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  27. Lumen is fast

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  31. 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 full-size slide

  32. 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 full-size slide

  33. Use it for
    Microservices
    duh!

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  36. The competition

    View full-size slide

  37. 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 full-size slide

  38. 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 full-size slide

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

    View full-size slide