Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

What I Do

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

What's a Microservice?

Slide 6

Slide 6 text

A Microservice should be Designed around a single business capability

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

! Microservices ! to the rescue

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Implementing a Microservice

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Immediate benefits

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Hold your horses

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Things to Consider

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

How big is your team?

Slide 28

Slide 28 text

Automation is key Development ➡ testing ➡ deployment

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

What is Lumen?

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

Lumen is fast

Slide 35

Slide 35 text

No, seriously! It's kind of the point

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

Use cases

Slide 41

Slide 41 text

Use it for Microservices duh!

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

The competition

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

Questions? Talk to me @MathiasHansen [email protected]