Microservices with Laravel Lumen

045dfdf10ef09f0eeaf9c4f0a27f5c6e?s=47 Mathias Hansen
November 18, 2015

Microservices with Laravel Lumen

PHP World 2015

045dfdf10ef09f0eeaf9c4f0a27f5c6e?s=128

Mathias Hansen

November 18, 2015
Tweet

Transcript

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

  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
  3. What I Do

  4. What We're Going to Do » Microservices, defined » How

    we're using Microservices at VB » Benefits and drawbacks » Microservices with Lumen » Questions
  5. What's a Microservice?

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

  7. None
  8. None
  9. We have... » A big monolithic app » A growing

    team » Concerns mostly separated » Let's go one step further
  10. ! Microservices ! to the rescue

  11. None
  12. Implementing a Microservice

  13. None
  14. Define a contract » REST? » Protobuf? » SOAP? (please

    don't do this)
  15. Plan ahead » How big should your service be? »

    How many services should you have? » Share common code across services » use composer
  16. Use an API Manager » api.videoblocks.com/search ➡ searchservice.internal » api.videoblocks.com/abtest

    ➡ abtestservice.internal » Authentication » Rate limiting » Usage tracking
  17. A Microservice Hybrid or go all the way? » Monolithic

    app + Micro services » Static Frontend + Micro services » PHP Gateway + Micro services
  18. Immediate benefits

  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
  20. Deployments, simplified » Deploy a "piece" of the app instead

    of full monolith » Independent deployment schedule
  21. Testing, simplified » Unit test » Internal functionality » Integration

    test » External interface » Load test » Ability to test each service individually
  22. Scaling, simplified Allocate extra resources to the service that needs

    it » Isolate hot/cold zones
  23. Hold your horses

  24. None
  25. Things to Consider

  26. Complexity » Increases complexity of your app » Network overhead

    » More planning necessary
  27. How big is your team?

  28. Automation is key Development ➡ testing ➡ deployment

  29. None
  30. What is Lumen?

  31. A microframework » But not necessarily in the traditional sense

    » Based on Laravel components » Follows Laravel versioning » Laravel Lumen 5.1 ➡ Laravel 5.1
  32. It still packs a punch » Blade (templating) » Caching

    » Commands » Controllers » Eloquent ORM » Dependency Injection » Queueing » Testing » And more...
  33. If you're familiar with Laravel, you already know how to

    use Lumen.
  34. Lumen is fast

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

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

    out of the box
  37. Routing » Uses nikic/FastRoute for routing » You don't need

    a fancy C extension to make routing fast
  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.
  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
  40. Use cases

  41. Use it for Microservices duh!

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

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

  44. The competition

  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
  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
  47. Questions? Talk to me @MathiasHansen mathias@videoblocks.com