We are considering moving from Forge to Vapor or from VMs to Serverless for a client. We are however not convinced that the startup in question will benefit from it. Not completely anyways. So I decided to make a list of what we have and what we think we will be needing for Laravel Vapor.
Background Story
Currently we are managing several Digital Ocean Droplets with Laravel Forge. Been doing that pretty well though we do have to deal with some downtime on server patches. We also have to turn off the Droplet to vertically scale it. We have not set up horizontal scaling with a load balancer and so on, but are considering this besides other options like containers and a serverless setup.
Serverless attracts us because it will allow us NOT to worry about the servers and focus more on our code. It will also allow us to deal a lot less with DevOps work. Simply because
- server maintenance will no longer be our problem
- the auto scaling of a Function as a Services or FAAS setup is very appealing as we would not have to worry about scaling things in advance.
- Lambdas can deal with millions of requests with relative ease.
- Only pay for what you are using, not more, not less
Forge Setup
We currently are using the Laravel Forge Growth package. The fee is $19 per month for this package. We use the more expensive team package from time to time but for the startup we do not really need it. Forge helped us
- setup solid servers,
- deal with Nginx, database restarts,
- PHP tweaks,
- database setups,
- tweak Nginx config
- finetune servers with custom recipes and
- general security.
Overall we have been very happy with it.
Digital Ocean Hosting
We use Digital Ocean as our hoster. Love the fact that the have ready made Ubuntu images that you can start up in no time. They also provide floating ip addresses, server monitoring, static assets storage and much more. Digital Ocean Droplets we have in use currently are:
- Staging 1 GB $5 +20% for backup
- Production Web 1 GB $5 +20% for backup
- Production Database 2 GB $10 +20% for backup
- DO Spaces 250 GB for app backups $5 per month
$47.26 per month at the moment including a few snapshots.
We are thinking about raising RAM for the production web server and we are considering a HA Proxy with script to scale horizontally, but we have not started with this as we are considering costs and other options as discussed. Vapor being the most appealing one at the moment. We are also considering moving more static assets to Digital Ocean Spaces.
Domain & Email Setup
Domains are with Transip as is email. We love the API they offer for booking domains, the large scale of domains they offer, especially in Europe. We were less happy with their VPSs so we are using Digital Ocean for that. So, here is what we have with them:
- New Webhosting Large €10 per month
- Domains (15 domains a.t.m.) costing around €150 a year
Why Vapor?
The reason why we were so happy to see Vapor is that though Serverless is very appealing it still is a pain settings things up with Lambdas, VPCs, Elasticache, RDS databases, domains and such. With Laravel Vapor’s GUI this has been automated for the bigger part with cool monitoring tools to spare.
Vapor Setup
- Amazon Account
- Amazon AIM User
- Vapor account – $39 / month or $399 / year https://vapor.laravel.com/
- installation Vapor CLI and Vapor Core
- storage – client file upload needs to be done with npm laravel-vapor, User Policy and custom forms
- static asset storage – better to separate asset storage by clients from app assets – both will need to be stored on S3
So besides setting up the account with Amazon and Vapor you need to install two packages. You also need to change the way files are stored as all static content has to be stored in S3. So not on your app server.
Amazon Hosting Costs – split per service
Amazons pay as you go service may be very liberating on one hand. In reality it is a true nightmare what you need for your part of the world. I spent hours going through what Vapor uses as minimal requirements and estimating what else we need to have our Laravel VueJS application run well and cost efficient on Amazon. Here are some of my findings.
NB We use the Frankfurt Region while Vapor seems to focus on the cheaper North Virginia region.
Amazon API Gateway Cost
APIs imparts an added value to the serverless functions by facilitating normalize access points for system functions, including security and monitoring. Considering the event-driven architecture, APIs help functions bridge service modelling among the systems by acting as an http endpoint to trigger your functions*.
- First 333 million $3.70
- Next 667 million $3.19
- Next 19 billion $2.71
- Over 20 billion $1.72
These free tier offers are only available to new AWS customers, and are available for 12 months following your AWS sign-up date. When your 12 month free usage term expires or if your application use exceeds the tiers, you simply pay standard, pay-as-you-go service rates.
- Amazon API Gateway API call charges = 5 million * $3.50/million = $17.50
- Total size of data transfers = 3 KB * 5 million = 15 million/KB = 14.3 GB
- Amazon API Gateway data transfer charges = 14.3 GB * $0.09 = $1.29
- Total Amazon API Gateway charges = $17.50 + $1.29 = $18.79
Load Balancer
Lambda Pricing
Lambda or Functions as a Service will be the base of our Vapor managed application. All functions will be executed here after they entered our place via the the Gateway API
https://aws.amazon.com/lambda/pricing/ & http://serverlesscalc.com/
- 1M REQUESTS FREE (free tier only)
- First 1M requests per month are free.
- $0.20 PER 1M REQUESTS THEREAFTER
If your application runs on a lambda that has 0.5GB (512MB) of allocated memory receives 2 million requests per month, and the average execution time is 0.5 seconds (500ms) each time, your get charged for 2 things:
Your Gigabyte-seconds, which is equal to the total Compute seconds * allocated memory. So in our example it’s 0.5 * 2,000,000 * 0.5 = 500,000 GB-s.
You get 400,000 GB-s for free each month so you’ll only pay for 100,000 GB-s which costs: 100,000 * 0.00001667 = $1.66.
You’ll also pay for the number of invocations, and you get 1 million invocations for free each month, so you’ll only pay 1 * 0.2 = $0.2.
So the total cost would be $1.66 + $0.2 = $1.86.
Looks cheap? Yes! But if you require execution time of 1 second instead, you’ll pay $10.2! Also the duration is rounded up to the nearest 100ms, so if the average execution time is 901ms you’ll still pay for the full second.
However, the CLI lambda is what you really need to watch out for. If you have a queued job that only requires 128MB of memory to run, while another job requires 3GB of memory, it doesn’t make sense to run the CLI lambda with high memory all the time. Instead you should consider splitting the heavy work into multiple jobs, so instead of running it inside a single lambda that requires a lot of resources, you just dispatch a chain with multiple jobs and Vapor will invoke the lambda once per job.
As we said earlier, Vapor converts your application to a single lambda. However, to allow you to set different configuration values for your HTTP and CLI environments, Vapor creates 2 identical Lambdas on AWS.
The HTTP lambda is responsible for serving HTTP requests; you can configure the amount of memory AWS should allocate to your HTTP requests, the timeout value, and the concurrency limit.
The CLI lambda is responsible for running artisan commands, processing queued jobs, and running scheduled jobs. You can also configure memory, timeout, and concurrency limits.
- https://www.simform.com/aws-lambda-pricing/
- https://techbeacon.com/enterprise-it/economics-serverless-computing-real-world-test
Route 53 Domain Pricing
- $0.50 per hosted zone / month for the first 25 hosted zones
- $0.10 per hosted zone / month for additional hosted zones
- $0.400 per million queries – first 1 Billion queries / month
- $0.200 per million queries – over 1 Billion queries / month
- $0.600 per million queries – first 1 Billion queries / month
- $0.300 per million queries – over 1 Billion queries / month
- $0.700 per million queries – first 1 Billion queries / month
- $0.350 per million queries – over 1 Billion queries / month
- .com $12
- .eu $13
- .net $11
- .org $12
- .us $15
- .nl $10
- .be $9
- .de $9
- .fr $12
- .co.uk $9
- .es $10
- .it $15
Domains are okay price wise but if we need to pay for a 10.000 domains and a hosted zone for each that would be 10.000 * $0.10 or a $1000 USD. So better to keep all with TransIP and or only use smart48 at Route53. That would mean only one zone and loads of A Names
See also https://aws.amazon.com/route53/pricing/
MySQL RDS On Demand Current
https://aws.amazon.com/rds/mysql/pricing/?nc=sn&loc=4
- ‘db.t3.micro’ => ‘db.t3.micro – (1 VCPU, 1Gib RAM) – Free Tier Eligible / ~$15 / month’,
- ‘db.t3.small’ => ‘db.t3.small – (1 VCPU, 2Gib RAM) – ~$25 / month’,
- ‘db.t3.medium’ => ‘db.t3.medium – (2 VCPU, 4Gib RAM) – ~$50 / month’, (0.069 per hr)
- ‘db.t3.large’ => ‘db.t3.large – (2 VCPU, 8Gib RAM) – ~$100 / month’,
- ‘db.m5.large’ => ‘db.m5.large – (2 VCPU, 8GB RAM) – ~$125 / month’,
- ‘db.m5.xlarge’ => ‘db.m5.xlarge – (4 VCPU, 16Gib RAM) – ~$250 / month’,
- ‘db.m5.2xlarge’ => ‘db.m5.2xlarge – (8 VCPU, 32Gib RAM) – ~$500 / month’,
- ‘db.m5.4xlarge’ => ‘db.m5.4xlarge – (16 VCPU, 64Gib RAM) – ~$1100 / month’,
- ‘db.m5.12xlarge’ => ‘db.m5.12xlarge – (48 VCPU, 192GiB RAM) – ~$3300 / month’,
- ‘db.m5.24xlarge’ => ‘db.m5.24xlarge – (96 VCPU, 384GiB RAM) – ~$6600 / month’,
- db.t3.micro $0.02
- db.t3.small $0.04
- db.t3.medium $0.08 $58 per month
- db.t3.large $0.16
- db.t3.xlarge $0.32
- db.t3.2xlarge $0.64
Amazon S3 Static File Storage
Amazon S3 Buckets are used to store your static assets like images, CSS, JS and such. On Digital Ocean it is called Spaces and both compete quite well price wise
https://aws.amazon.com/s3/pricing/
- First 50 TB / Month $0.0245 per GB*
- Next 450 TB / Month $0.0235 per GB
- Over 500 TB / Month $0.0225 per GB
- Up to 1 GB / Month $0.00 per GB
- Next 9.999 TB / Month $0.09 per GB
- Next 40 TB / Month $0.085 per GB
- Next 100 TB / Month $0.07 per GB
- Greater than 150 TB / Month $0.05 per GB
Amazon SQS Pricing
https://aws.amazon.com/sqs/pricing/
- Region: Frankfurt
- Pricing per 1 million Requests after Free tier (Monthly)
- Standard Queue $0.40 ($0.0000004 per request)
- FIFO Queue $0.50 ($0.0000005 per request)
- Up to 1 GB / Month $0.00 per GB
- Next 9.999 TB / Month $0.09 per GB
- Next 40 TB / Month $0.085 per GB
- Next 100 TB / Month $0.07 per GB
- Greater than 150 TB / Month $0.05 per GB
Amazon VPC / NAT for private database
Elasticache
- cache.t2.micro 1 0.555 Low to Moderate
- cache.t2.small 1 1.55 Low to Moderate
- cache.t2.medium 2 3.22 Low to Moderate
- cache.m4.large 2 6.42 Moderate
- cache.m4.xlarge 4 14.28 High
- cache.m4.2xlarge 8 29.70 High
- cache.m4.4xlarge 16 60.78 High
- cache.t2.micro $0.019 – $13.7 per month so similar or close to North Virginia region as in https://github.com/laravel/vapor-cli/blob/master/src/CacheInstanceClasses.php
- cache.t2.small $0.038
- cache.t2.medium $0.078
- cache.m5.24xlarge $8.928
- cache.m5.large $0.186
- cache.m5.xlarge $0.371
- cache.m5.2xlarge $0.741
DynamoDB
- Write request units $1.525 per million write request units
- Read request units $0.305 per million read request units
This is excluding transfer fees
More information on this is needed..
source https://aws.amazon.com/dynamodb/pricing/on-demand/
CloudFront CDN
Cloudfront we use for a CDN and also to see on bandwidth in general
- First 10TB $0.085
- Next 40TB $0.080
- Next 100TB $0.060
- Next 350TB $0.040
- Next 524TB $0.030
- Next 4PB $0.025
- Over 5PB $0.020
Cost Estimate
- API Gateway 5 million api requests, 3KB Cache ~$20
- AWS Lambda*- x 2 ~ $20
- MySQL RDS t2 micro 3 in one ~ $15**
- DynamoDB Caching ~ $5
- Amazon S3 250 GB $5
- Cloudwatch Logs (Lambda & API) ~$5
- Cloudfront – 50GB ~$5
~$75 per month excluding $39 Vapor costs
Total ~$114 USD a month
*2 million executions, 1024 MB Ram, 500 ms execution time, including free tiers
**we can have a base database, published and backup on one instance – there is no limit
Conclusion
So as you can see the current setup with Forge and Digital Ocean VPSs is considerably cheaper at $67 a month. Almost twice as cheap. Vapor / Lamda functions however offer considerable performance advantages.
So.. to migrate or not to migrate. We have not made up our minds yet. This as we also need to take into account code changes to deal with a different storage setup as we cannot store on disk but need to store on S3. That and migration in general which is always painful.