Scott Keck-Warren
0:05
Hello, developers, and welcome to the Community Corner podcast where we have conversations with members of the web development community. I'm your host, Scott Kaack Warren, and today we're talking with Nelson Isoma about serverless architectures. Nelson Isoma is a product engineer of— with 5 years experience. He is also passionate about open source and giving back to the community. Thanks, Scott. Thank you, Nelson, for finding some time to talk to us today.
All right. Thanks, Scott. It's nice to be here.
Scott Keck-Warren
0:29
Yeah, absolutely. So the reason that we brought you on is because you have an article in the November 2024 issue of PHP Architecture about building serverless PHP applications. Can you talk to us a little bit about what serverless PHP applications are?
Okay. So serverless PHP applications are once you write your PHP code for your web application or your API, you don't have to worry about deployments. So you just pick your serverless framework or provider and then you give them your code and then they handle deployments, they handle automatic updates. And then if any server patches or fixes that might happen or you might need, all are going to happen automatically without you having to learn like the DevOps side of things. So it simplifies work a lot for, let's say, small startups, indie hackers, and people of that nature.
Scott Keck-Warren
1:18
Okay. And so, so the idea basically is like, when, like, I usually want to like, okay. When I was younger, I should say, um, like we would have to like get a server and then we had to install the operating system and then all the packages and we need and stuff. And like this, like just completely removes that piece of it, right? We're just saying, here's some code, please run this code.
Exactly. That's how it works.
Scott Keck-Warren
1:38
Okay. And then, so what is a good use case for, for a serverless, uh, application?
Okay. So serverless comes with some problems which I went in great detail earlier in the article. But so good use cases for serverless would be you have like a piece of code that you don't have to run every time, maybe an event function. Let's say something like you have a bucket and when the S3 bucket's updated, you want like a piece of code to quickly run. That's a good use case for serverless. Then because of cold starts, if you are someone that's not really worried about cold starts, then you can pretty much use serverless for anything. So if you have like a small app you want to share with your friends, put it on serverless and then it works basically. Then, um, what other use cases? Um, so I think those are the 2 main times I think I would recommend serverless. So you have like a piece of code you want to run when an event occurs, or you have like, um, a web application that, uh, you're not really— you don't really worry about latency because you could just use serverless in that.
Scott Keck-Warren
2:42
So, and so, so could we talk about like that, like putting something in a bucket piece? And so I think like one of the things that I've found very fascinating about modern development is that like, we've gone away from here's one giant like application into like smaller and smaller and smaller pieces. Like, right. We had like, we started out at a big application, then we're in microservices. Now we're looking at like, just like one tiny little thing might be all that this serverless thing is doing. Right. So, so like, so like your example was like image processing. And my favorite one is like, I wrote, I'm gonna edit this podcast and then I'm gonna upload it. process that handles that. So, that would be like we could do background processing of files and stuff, right? Is that a good use case?
Yeah, that's a good use case. So, you could have a setup where after this video is recorded, you have to notify your users that, oh, we uploaded a new video. So, you could use serverless in that situation. Or if you want to do some processing, maybe reduce the quality for smaller devices and stuff like that, Lambda serverless will also work in that scenario.
Scott Keck-Warren
3:45
Okay. And then the cold start, can you talk us through what is a cold start?
Oh, okay. So why serverless is cheap is because you only— so the way cloud providers say it is billable hours or billable minutes rather. So your function is not— your code is not always available. It's not always deployed, right? So when a request is made to your application, the cloud provider has to boot up your app. So it has to start it up, load the OS, load all the necessary packages, and then run— deploy your code basically. And then once the request is handled, the server would slowly bring it back down basically. So that's where cold starts come from. So the latency that it would take for the OS to get boot up, the packages to get installed, that's what causes cold starts. So it could take like, let's say a couple of milliseconds. So it's not too much of a worry.
Scott Keck-Warren
4:41
But it, but it could be like, you don't wanna run like your, like a huge, like high demand website, like based on it, right?
Exactly. Yeah. If you have something super real time that you need to be on 24/7, then you definitely don't need serverless.
Scott Keck-Warren
4:54
But it would be, it's definitely good for something that you do like occasionally or, or, or like, you know, you might do like 6 times an hour and then be, and not do it at all.
Exactly. It's, it's much cheaper and it works very wonderfully in that scenario.
Scott Keck-Warren
5:08
So is this something that like, is like, are, what are my options for going to like a serverless architecture? Like, do we have, are there multiple providers that are giving us this or is it, is it just kind of limited to a few?
Okay. So, um, there are multiple providers. Uh, we have AWS, we have GCP, we have Azure, but then some of them don't support PHP natively. So you, so they, but they create like a run, an OS-only runtime where you can then install PHP in. And then, so serverless is really broad. So depends on how much work you want to do. So if you don't, if you still want to be involved, kind of involved in the process, you could use AWS or GCP. But then if you want like a totally stress-free situation and you want to just take my code, put it on the internet, then there are also providers that offer that like Laravel Vapor and Railway and Fly.io. And then if you're looking for something open source, you can use Bref and a couple of others as well.
Scott Keck-Warren
6:09
Oh, that's cool. So how is it that like you as like a day-to-day, like during your day-to-day like job, like what is it you use serverless for?
Okay, so we had, we actually had our entire API on serverless. I think that would not be like the best approach for most people. what it worked for us basically. So my previous role, I worked at Treble and we had like, was it, we were like an observability startup. Definitely check us out. So what we did basically was you load in our middleware, our package, and then any request that comes into your application, you see it on a dashboard where you can go through these requests. We also catalogs and a ton of other features. So in that scenario, we needed we needed serverless. So our customers are not using the API every time. So let's say some days there are spikes and some days they're like not that much use at all. So we had the whole API deployed in Laravel Vapor serverlessly. And then, but to mitigate cold starts, we had to create like concurrent instances. So we had like more instances like than the average serverless user. And it worked really great for us.
Scott Keck-Warren
7:26
That's really fascinating. 'Cause I, I, I, um, and I'm, I am not using serverless. Like we, we have like a, an infrastructure where like it doesn't work for us, like essentially like in, um, but it definitely is something that like I want to start trying out, especially since like, like those cases of like, well, we have a file and we need to process this file, right? Like we have that situation like a lot where we like get some sort of file and it would be nice to have like a, here's like a very simple thing that just does this one tiny little bit. So it's definitely something for, for me to check out. I, I don't, I suggest our listeners also. There's a good overview in, again, in the September— I'm sorry, in the November 2024 issue of PHP Architect. So it's really like a fascinating read. So is there anything else that you'd like to direct our listeners to before I let you go today?
Okay. So I think I'd like if you guys follow me on Twitter. I talk about what I'm working on, mostly PHP, Laravel, and Go related sometimes. I have this really cool CLI tool I just worked on. So it's like a port scanner. I don't know if you could like drop a link in the podcast later, but it's like a port scanner. So if you're someone like me that forgets ports open on your Mac, you can just like scan for the open ports and then you can also kill, like close the ports basically using the port scanner tool. So it's a really handy tool and yeah. So I would just really be happy if What if it's 10 people or 5 people, uh, they read through the article and they're like, wow, serverless is really cool. And then they try it out and I'll be really grateful and I'll feel like I've done a good job.
Scott Keck-Warren
9:02
Yep. And we'll, we'll include links to those in the description. So yeah. Awesome. So thank you for, for finding time to talk to us today. I have to say another heartfelt thank you to Nelson and to you for finding some time to listen to us today. If you're not already a subscriber, make sure you subscribe with whatever your preferred method is so you can get the episodes as soon as they're released. Maybe share this post with your coworkers so they can learn from it as well. This podcast is available both as an audio version on the PHP Architect website, as well as a video version on the YouTube channel. This is Scott Cack Warren for the Community Corner podcast, signing off and reminding you to keep listening, keep coding, and keep reading.