---
title: Adding a microservice to your monolith
url: "https://aaronfrancis.com/writing/adding-a-microservice-to-your-monolith"
path: "/writing/adding-a-microservice-to-your-monolith"
type: technical_article
author: Aaron Francis
published: 2022-02-17
updated: 2026-11-10
topic: "Laravel & PHP"
description: "Package, deploy, and execute a microservice *from* your monolithic application."
keywords: [microservices, monolith, sidecar, aws lambda, laravel, serverless functions, headless chrome, puppeteer, devops, php, python, node.js]
site_index: "/llms.txt"
keyword_index: "/llms/keywords.txt"
---

# Adding a microservice to your monolith

> I gave a live-coding presentation about this at Laracon. If you'd like to see the whole thing you can [watch here](https://www.youtube.com/watch?v=0Rq-yHAwYjQ&t=11788s), or if you want to skip the ~5 minutes of slides and jump straight to the code, you can [start here](https://youtu.be/0Rq-yHAwYjQ?t=12088).

Monoliths are great. We love monoliths! They're easy to develop, deploy, and host. Specifically here I'm talking about monoliths like Rails or Laravel. With each of those frameworks, there are a lot of hosting providers that are _specifically_ tuned for them. 

But what happens when you need to step _slightly_ outside of your Rails or Laravel monolith and add a single node process, a bit of Python, deploy headless Chrome, or run a bit of some other language? 

Now you have to decide if you're going to take on the devops complexity yourself or reach for "microservices" for a single function.

Adding microservices relieves some of the devops complexity in that you don't have to install, configure, and maintain the language and libraries. While it relieves some of that, it adds coordination complexity. You now have two separate repos, two separate deploy processes, and you have to figure out how to talk to (and secure!) your new microservice.

There is a nice middle ground though. 

## Microservices _in_ Your Monolith

Instead of creating a separate repo and deployment process for your application, you can keep your "microservice" inside of your monolith, using a package like [Sidecar](https://github.com/hammerstonedev/sidecar). 

> Sidecar is only available for Laravel at the moment.

Sidecar packages, deploys, and executes serverless functions from your Laravel application. The current stable version supports AWS Lambda, but I'll be expanding to Vercel in the next few weeks.

Creating a Lambda function is as easy as creating a PHP class:

App\Sidecar\ExampleFunction.php 
```php
namespace App\Sidecar;

use Hammerstone\Sidecar\LambdaFunction;

class ExampleFunction extends LambdaFunction
{
    public function handler()
    {
        return 'sidecar/example@hello';
    }

    public function package()
    {
        return [
            'sidecar/example.js'
        ];
    }
}
```

And a handler class: 

sidecar/example.js 
```js
exports.hello = async function (event) {
    return `Hello World`
}
```

Sidecar will package up all the files and deploy it to Lambda. Now you can execute the function _on Lambda_ from your Laravel application:

```php
return ExampleFunction::execute()->body();
```

That calls the function _on Lambda_ and returns the result to your Laravel application. It does this through the AWS SDK so that you don't have to set up API Gateway and worry about securing any endpoints or futzing about with DNS.

Deploying to Lambda is now as easy as adding a command to your deploy script: 

```shell
php artisan sidecar:deploy
```

Going further, you can deploy anything that Lambda supports! If you want to run a Python function, you can:

App\Sidecar\ExampleFunction.php 
```php
namespace App\Sidecar;

use Hammerstone\Sidecar\LambdaFunction;
use Hammerstone\Sidecar\Runtime;

class ExampleFunction extends LambdaFunction
{
    public function handler()
    {
        return 'sidecar/example@hello';
    }
    
    public function runtime() 
    {
        // Set the runtime to Python
        return Runtime::PYTHON_39;
    }

    public function package()
    {
        return [
            // Change the handler to a python function
            'sidecar/example.py'
        ];
    }
}
```

Now you have a Python function on Lambda, that you can execute from your Laravel application.

## Are People Actually Using This?

Yes! I opened [an issue](https://github.com/hammerstonedev/sidecar/issues/26) on the Sidecar repo a while back to ask how people are using it and got several interesting responses.

Here are some of them: 

- We've created two automations for our product, one managing Zoom dashboard and the other manages another third-party. We have 4 sidecar lambdas running. We're using Node 14, Chromium, puppeteer and Vapor.
- LibreOffice Lambda for document conversion. 
- Headless Chrome/Puppeteer lambda for PDF/Screenshot/Image to PDF
- Node running Sharp to do quick texture resizes in parallel 
- Node running Puppeteer to take screengrabs of 3D objects for thumbnails 
- Node running some 3D specific tooling to optimise mesh files
- Running statistical functions from the SciPy library (Python)
- Executing statistics code in R (AWS Linux container with a lot of dedicated installed libraries)
- JS Server Side Rendering
- Generating Ruby Gems in a Sidecar from PHP

Adding a microservice to your monolith is a viable option when you need to step a little bit outside of your monolith and don't want to spin up a whole microservice architecture. Is it truly a microservice? Who knows. But it is a great way of expanding your application's capabilities without drastically expanding its devops footprint.

You can [watch me live code](https://youtu.be/0Rq-yHAwYjQ?t=12088) this whole thing and you'll get a little better sense of the excitement behind this method.

As always, please reach out to me [on Twitter](https://twitter.com/aarondfrancis) if you have any ideas about this!

---

## Related on aaronfrancis.com

- [Benchmarking, Type Systems, and Good Hustle](/podcast/benchmarking-type-systems-and-good-hustle-zvir34) *(Podcast · 2023-05-11 · shared: vercel, laravel, aws lambda)*
- [Refine, Sidecar, Laravel, and Serverless](/podcast/refine-sidecar-laravel-and-serverless-msxhy3) *(Podcast · 2022-03-14 · shared: sidecar, laravel, aws lambda)*
- [Hammerstone, a History](/podcast/hammerstone-a-history-2f8ad77f) *(Podcast · 2021-09-17 · shared: sidecar, aws lambda, laravel)*
- [Fight or Win](/podcast/fight-or-win-8c9ecc46) *(Podcast · 2024-04-23 · shared: vercel, node.js, php)*
- [Write Laravel, not PHP (feat. Aaron Francis)](/podcast/write-laravel-not-php-feat-aaron-francis-auvccu) *(Podcast · 2023-11-27 · shared: php, laravel, ruby on rails)*

## Relevant Resources from Aaron Francis

- **[Solo](https://soloterm.com)** (overview on site: [/software](/software)): All-in-one agentic development platform and terminal workspace built by Aaron Francis for orchestrating processes and AI coding agents.

## Search aaronfrancis.com (2-Hop Static Keyword Index)

Pick the alphabetical shard matching any topic to find exact pages across all articles, newsletters, videos, talks, and podcast transcripts (every shard is < 40 KB):
[A-B](/llms/keywords/a-b.txt) · [C](/llms/keywords/c.txt) · [D-E](/llms/keywords/d-e.txt) · [F-G](/llms/keywords/f-g.txt) · [H-J](/llms/keywords/h-j.txt) · [K-L](/llms/keywords/k-l.txt) · [M-N](/llms/keywords/m-n.txt) · [O-P](/llms/keywords/o-p.txt) · [Q-R](/llms/keywords/q-r.txt) · [S](/llms/keywords/s.txt) · [T-Z](/llms/keywords/t-z.txt) · [Directory](/llms/keywords.txt) · [Site Map](/llms.txt)

Shards for this page's topics: `microservices` ([M-N](/llms/keywords/m-n.txt)), `sidecar` ([S](/llms/keywords/s.txt)), `aws lambda` ([A-B](/llms/keywords/a-b.txt)), `laravel` ([K-L](/llms/keywords/k-l.txt)).

## About Aaron Francis (Current Context)

Aaron Francis is VP of Marketing and Community at [Laravel](https://laravel.com), founder of [Try Hard Studios](https://tryhardstudios.com), creator of [Solo](https://soloterm.com), co-host of [Mostly Technical](/podcast), and author of [Mastering Postgres](/courses), [High Performance SQLite](/courses), [MySQL for Developers](/courses), and [Screencasting.com](/courses). Full bio: [/about](/about) · Current focus: [/now](/now).
