A bank runs serverless with PHP and AWS Lambda
bref.sh
bref.sh
I do wonder how they came to Lambda though. I love it for small workloads and highly variable demand services, but something like Treezor you'd think has relatively flat and high demand. The cloud cost for Lambda would be much higher than running the equivalent compute, even with something also highly scalable like ECS.
I'd imagine a bank has quite a few of these sorts of bursty bash processing needs; ACHes, end-of-day reconciliation, etc.
How expensive our your cloud costs? CI/CD pretty good?
Cost-wise we're pretty bursty, so it's saved us quite a bit. Lambda runtime is money, so a little bit of performance optimization can go a long way. CI we run through Github Actions; an environment secret plus `vapor deploy` and it's on its way up after a successful run.
Wasn't a fan of Forge; for that style of things I'd use Ploi nowadays.
As I understand it, banking commonly uses JVM where you can easily do async or multithreaded processing and task scheduling, so lambda doesn't offer much over ECS, and the timeout could be a real killer.
even the 'non' batch things were done in batch (even if it's do now, and only 1).
You can have a single queue gathering workloads and then have Lambda functions grab a bunch of tasks, handle them, grab more etc. until the max runtime is met and they're automatically rebooted.
It's also pretty trivial to add more processing capacity when the queue goes over a specified limit just by allowing for more concurrent Lambdas.
And when there's nothing to process, you've got one idling Lambda doing nothing and costing nothing.
1000 lambdas with 1000 database connections is also going to be a horrible way to do things on the backend. Add in the cost of RDS proxy for lambda and the ECS solution becomes even better.
I personally don’t think running on EC2 is particularly difficult to manage, and it’s even cheaper again.
So yes, very expensive fast if you get much traffic at all. That c6g.large should easily be able to handle dozens (if not hundreds) of requests in parallel, especially if many of those requests are going to have to wait for results from a database.
If you have more than ~800 hours of Lambda execution time per month (30 days being 720 hours), then you're better off with the c6g.large. The only reason to choose the Lambda is if your traffic is extremely bursty and the c6g.large can't handle the load.
Of course, this is all assuming you're using a 1 GB Lambda. Likely, your Lambda needs less, in which case the amount of traffic needed to make the EC2 more worthwhile higher.
If you want to compare AWS Lambda with EC2, you need to bring in AWS Load Balancer, Auto Scaling, Security Upgrades for the OS, Healthcheck and many more.
Yes, Lambda is not needed in a lot of context, but if you have the expertise to use it and you want to provide enterprise-grade compliance, it's a walk in the park.
Bringing the long-lived server back also makes things like long-lived connections, memory caching, cold starts and database connections a non-issue again.
The costs certainly are not as cut-and-dry as I originally expressed it.
[0] https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-...
This has been scaling really well for us and affordability wise it makes the development and testing phase basically free, with the final deployed costs almost never exceeding double digits monthly. This is for multi-az + multi-region deployments too.
> infrastructure must be able to scale and be resilient to accommodate various usage patterns. Whether it's a luncheon voucher transaction spike at lunchtime or a monthly batch of transactions by corporate clients
Probably some security certification that AWS Lambda comes with. I worked at Cambia Health that used Lambda (Javascript) for dealing with customer mobile data. It was a nightmare solution (cost and complexity) for what should have been a simple fan out queue and process system. They hired me to help fix it. Every other solution was a flat no. AWS Lambda was was HIPPA compliant (for whatever that's worth) and some other security assurances that I don't remember, so I was basically just another developer (with a moron for a manager).
Probably misplaced hype about being fully serverless.
As you said, ECS would be much more suitable while also addressing the issue that they had (spikes in traffic).
Lambdas behind API Gateway sounds like a good idea and even looks like one if you don't have experience with ECS and don't do a proper cost comparison analysis.
My team uses ECS' autoscaling to scale up to tens (or even hundreds) of thousands of tasks in minutes without issues.
I wouldn't lift-and-shift the PHP app I work on, it requires too many FreeBSD-specific/custom underlying services but I could make use of lambda for certain tasks while leveraging the PHP code we already have. We use SST for for some NodeJS (TypeScript) lambdas that have been very popular but PHP isn't going anywhere in our stack so I'd love to find a way to move the bursty parts of it to lambda.
I'm having trouble understanding where PHP fits into this scenario. If your cloud backend is in PHP, can't you just host that anywhere, separate from your frontends? Where does the serverless come in? And which did you use? (There are so many out there now, from AWS Lambda to Cloudflare to Fastly, etc.)
If you're not limited to AWS, Google's Cloud Run lets you containerize a PHP app and auto-scale it up and back down to zero in bursts, for example. It's not really serverless, just an auto-scaling VM that goes up and down as needed.
edit: google cloud functions might be even closer: https://cloud.google.com/functions/docs/create-deploy-http-p...
Yes, that’s the correct SST. Yes, we could host our PHP anywhere and there are options like Cloud Run. We are on AWS and so I was talking about AWS Lambda but I understand that wasn’t clear at all.
The reason for wanting to use Lambda is for bursty/inconsistent workloads. We have EC2 servers that handle all our traffic right now but some are oversized to handle the peaks. There are parts of our system that we could easily offload to lambda to reduce the load on the main servers if we could easily run PHP in lambdas.
I’m going to take a look at the CDK example OP posted (sibling comment to yours) since SST is just a layer over CDK and you can reach down into CDK easily.
Have you also looked into Elastic Beanstalk? It's an older AWS service but it's made to help you handle bursts or scheduled peaks.
I've found PHP with Laravel a stable and solid workhorse. Good for getting things done quickly, and then a stable system over time.
In contrast, I've gradually become disillusioned with the node.js and JavaScript/TypeScript ecosystem over the years. You can build quickly, but the systems turns into a pain to maintain and update.
The PHP ecosystem on the other hand tends to be less fragmented and these days with frameworks like Laravel the code is generally also pretty good. I think it gets a bad reputation because in the 00s there were some truly horrific PHP projects out there and the language itself was quite immature and poorly designed. That's not the case anymore though. These days I struggle to understand the hate it gets. It's certainly no worse than than Node.
> To do a controlled migration, the team deployed the application both to the servers and to AWS Lambda. Only 10 lines of code needed to be changed to run the monolith on AWS Lambda.
Part of choose boring is more about choose the right tool.
Would you build a PoC webapp by having AI generate Rust? Or, just bang out a few lines of PHP or JS? If the objective is to build a working business tool it's choice B; if the objective is to test AI making Rust then A
I really enjoy PHP because it's easy to prototype in, there are a plethora of highly useful libraries for it, it has quite a few mature frameworks[1] and the language syntax is quite powerful.
1. Laravel gets a lot of attention but I'm a huge fan of Zend/Laminas.
I've tried to leave, I've explored outside the relationship. I've dealt with thorns and rough edges. But I've grown, the language and ecosystem have grown and it's been _wonderful_. I truly consider _not leaving_ the PHP ecosystem when I gave an earnest effort to explore elsewhere one of the best decisions I've ever made.
I love to build cool shit and PHP makes that _ridiculously_ easy.
PHP 7+ (the language) was wonderful, especially compared to Javascript's woefully inadequate standard library. It had so many helper functions that made even working with JSON and big data objects much easier.
But having to manage its buildchain wasn't fun (meaning needing to containerize a web server, PHP-FPM, etc. for every trivial deployment). Then needing to support an OS behind it with updates and such, even Dockerized.
For serverless in particular, the availability of V8 isolates (like in CF Workers) or other "just run this snippet of code and don't bother me about the infra" services (like Lambda) or "I can host my serverless in a file alongside my other frontend stuff" (like on Vercel/Netlify) means that JS functions are pretty much zero-config 1-click deploys.
Is there anything like that in the PHP world? For Bref, for example, you have to set up a lot of stuff before the serverless will run: https://bref.sh/docs/setup
For Google Cloud Run (which supports auto-scaling containerized PHP, not true serverless but closer to it than a full VM), you have to manage docker: https://cloud.google.com/run/docs/quickstarts/build-and-depl...
Maybe the closest one I know of is a Google Cloud Function (https://cloud.google.com/functions/docs/create-deploy-http-p...) which comes close to the "function as a service" of JS serverless, but you still at a minimum have to deal with a tiny folder structure (index.php + composer.json).
Is there anything similar on AWS or elsewhere?
Lots of companies or "neobank" that want to offer a kind of bank account, for personal or corporate use, but that don't have an official banking agreement, and not really a banking infrastructure, can use them as "white label" solutions.
All the bank accounts and banking operations will be done by treezor, but from the user point of view, he will only interact with the company and company frontend, and almost never see that it is Treezor that is operating in the background.
That being said, I don't know if their "serverless" move is a good one, because their solution is commonly known to be unreliable, and I think a lot of customers would be happy to go to another provider if it was possible.
I have immense respect for the author, but I'm perplexed about the decision to build a bank on this stack.
Especially considering that the person who created Laravel Vapor (a serverless Laravel service) has since discussed the advantages of moving a large project from Lambda to EC2 (https://twitter.com/themsaid/status/1716844479817154589).
I really do wonder what the bullet points of pros/cons in choosing to go serverless for something like this were.
For a smaller site with bursty traffic, Lambda may be very relevant still.
Ain’t that always the way
So, is this a payment processor much like Stripe?
So it means that if I connect to treezor.com, I am not talking to a server, but it's direct communication with god in heaven?
And it's not a badly configured server, but the Content "Security" Policy allowing FOURTY different sites, including unsafe inlines (!) is beamed into my brain from a different universe?
And the PHP "software" also clearly is running on a server, because PHP isn't a server-side scripting language, it's all happening in your mind!
/s
Hint: The whole point of a bank is BEING a server, be a central trusted authority accepting and executing transactions from and between clients. A serverless bank is a bank that no longer exists, but got replaced by peer-to-peer transactions.
Yes, there is a computer. Good job, you pointed it out. No one is paying AWS money because they think amazon is somehow running code without computers being involved. They’re paying to run lambdas to avoid dealing with the computers that run the code.
Banks specifically have much higher operational costs due to regulatory requirements. Banks like to focus on their financial strategy and outsource the rest.
I am nitpicking because there are technically uneducated people (managers) who actually believe in these BS marketing terms. People who already thought that such a thing as a "cloud" exists, resulting in us now having to look at our personal data getting stolen once per week because some manager thought you no longer need competent system administrators, because you are just pushing that personal data "to the cloud", so no risks involved.
And in this regard, the term "serverless" is even worse. It's basically the flat earthers of technology.
These BS marketing terms like "cloud" and "serverless" are an excuse for managers to act in an irresponsible fashion, thinking competence is no longer needed in-house. But competence IS needed.
And that's why every single person of "us" in each and every conversation should point out "you are putting the data of your customers and your businesses existence into the hands of someone you don't know at all" and avoid the BS marketing terms. If we go along with them, we are just hurting us, our employers, customers and/or clients, and humanity.
So, in this case the article should be translated into:
"Our intern wrote some crappy PHP shit because he is not really a programmer but a baseball player, and we have decided to just upload and expose all our stuff to some random organization at an unknown location under unknown control so we don't have to deal with this stuff anymore once the intern has left."
:)
1. we're a small team and we want to manage as less infra as possible 2. with their "dev mode" docker images, we can a local version which replicate 99% of the production environment (same runtime, same readonly filesystems etc.) 3. deploying is as simple as doing a zip , uploading to s3, and calling lambda update. 4. we have cronjobs with cloudwatch , Symfony's Command.
Anyways, if companies are going to use made up words for their names I'm happy to always deny them the benefit of the doubt.
"Let's go h4x0r all the tr33z0r5 for the logz"
Also... what has the bill been like? I've used Lambda for side-car data migration projects but I'd be surprised if it saved money over a beefy co-located or cloud server if your volume is generally constant.
Actually, it's easier. AWS RDS with multi-zone failover and replication + backups with retention schedules, deletion protection and legal holds... easy as a cake, less than 100 lines of Terraform code. And no risk of insider threats deleting, manipulating or ransoming the backups.
I wonder if you can build something like this entirely greenfield today, like what you'd use as a permanent data store for all the transactions, without having to manage the scaling of each individual microservice. Would CF Workers + Durable Objects be able to handle something like that?
Is this really such a big niche? It's weird to me to you'd want to use PHP for something like this (and I love PHP, it just doesn't strike me as the best tool for serverless).
For context, 13B is like roughly a <strike>$2000</strike> (edit: more like $4000, sorry) spend on Cloudflare Workers, similar cost (harder to calculate but ballpark similar) on Lambda. That could be a single company spending the bulk of that.
(Further edit: Lambda pricing is way off too. See reply below.)
How come Lambda is so expensive for you?
At 13000M invocations/mo, that's $2600 in requests. Is it the GB-seconds duration charge that get you?
60'000'000 requests
1536MB RAM
300ms response avg
(calculation includes free tier):
Request costs: $11.80/month
Execution costs: $443.42/month
Total AWS Lambda costs: $455.22/month
Unlike Node, Python, Java, etc. that start a long-lived server, each request is handled by PHP in a separate process.
That's what makes it really to use with serverless (and lift-and-shift, like what Treezor did).
Comparing Bref (https://bref.sh/docs#maturity-matrix) which inherits Lambda's 200ms+ cold starts vs Cloudflare's 5ms (https://blog.cloudflare.com/eliminating-cold-starts-with-clo...), for example, is a pretty big difference.
But I guess if performance isn't a critical use (or you just have so many invocations all the time in every data center that cold start isn't an issue), it's nice to be able to ~port~ copy and paste over your existing PHP code.
im honestly amazed how bad almost every bank service is with their tech usage... and this has been true for all of my living memory.
i might have to look into these guys... maybe i can have a service thats only millions of times worse than i expected as a child, instead of trillions of times worse
Is it that common around the world and 'we' just happen to have been overkill on security or do they are not really a true 'bank' and more a payment provider ?
that seems such a change from some years ago were cost were totally the last of the issues against security.
Heck, even for the classified stuff, I heard Azure built a government owned datacenter running a self hosted copy of their software. Much better quality than asking some Gen Dynamics contractor to manage everything for you.
https://aws.amazon.com/financial-services/security-complianc...
Certainly I would trust AWS with my information more than my bank. My bank is only trustworthy because we have regulations limiting my liability for unauthorized charges... without that I would never trust my bank (or Paypal, for that matter) to hold my funds. These are the same people that still use magstripes and publicly-visible numbers to authorize transactions, after all. Of all the services I've used, my bank is the only one that regularly gets its info stolen (credit card fraud). Thankfully the law doesn't let them hold me responsible for the charges.
My credit union is lackluster but that’s expected I’m not there for their mobile apps.
I miss Simple :(
This isn't a step up from "nothing", mind. Initially, I used to have some kind of OTP fob for paying online. They then moved to SMS. Then to their app attached to my iphone. Now, back to SMS. I still have the app installed on the same iphone, and I use it regularly.
I bet they will never fully migrate (and they don't want to).
Not affiliated with ING in any way, its just what I heard.
A imho healthy aspect of the move towards public cloud is to start with an exit strategy. This is turning out to be quite tricky. Some services though can be sourced from public cloud (ci/cd, ticketing, planning etc) but core workloads not so easy.
Other satellite services and applications are migrated to the cloud or SaaS, but the core is an old school mainframe, solid and tested to the last bit.
The main concern from the regulator perspective isn’t security as much as concentration of risk in a small number of providers: if AWS goes down, will it take the whole financial sector with it?
Why? Why do people insist on doing this? Move something less important first, prove you can operate in production, then move the crown jewels.