Migration from Forge to Vapor

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

If we would be accepted to Vapor and choose to go for it how much would we be paying for Vapor and Amazon fees? Now, that is quite a tricky business with pay as you go services such as Lambdas, SQS queues, Cloudfront CDN, Elasticache, RDS databases and such.
 
So what is needed to get going with Vapor? Vapor has packages to make your Laravel application work with Vapor / Amazon FAAS. But some tweaks are needed still. Here the shortlist
  • 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*.

* Simform article

 
The Amazon API Gateway free tier includes one million API calls received for REST APIs, and one million messages and 750,000 connection minutes for WebSocket APIs per month for up to 12 months.
 
If you exceed this number of calls per month, you will be charged the API Gateway usage rates.
1M API CALLS RECEIVED | 1M MESSAGES | 750,000 CONNECTION MINUTES per month.
 
  • 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.

First 333 million $3.70.
 
NB For more efficient API calls you can also use caching.
NBB External Data transfer not added here
 
Example
  • 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
 
However, for applications that receive more than 6 million requests per month constantly, the pay-as-you go model doesn’t really work. For this, Laravel Vapor allows you to provision a Load Balancer where you pay AWS a flat rate for every hour the Load Balancer is up ($17/month roughly) + charges for something they call (Load Balancer Capacity Units) and you can receive any number of requests*.
 
 

Load Balancer

As an alternative to API Gateway, you may route traffic to your application using an Application Load Balancer, which provides large cost savings at scale. For example, if an application receives about 1 billion requests per month, using an Application Load Balancer will save about $4,000 on the application’s monthly Amazon bill.

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
$0.0000002 per request
 
Here feedback from Diving into Laravel by Said
 

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.

 
* similar to Bref
 
HTTP Lambda via API Gateway and the CLI Lambda is activated when SQS sends queued jobs. Schedules are managed with Cloudwatch and Vapor creates rules for them that will start the CLI Lambda.
 
More sources

Route 53 Domain Pricing

Here you pay as you go and the setup is rather complicated / fine grained. You pay for hosted zones, dns queries, domain management. Latter is standard anywhere, but the first two are not.
 
  • $0.50 per hosted zone / month for the first 25 hosted zones
  • $0.10 per hosted zone / month for additional hosted zones
 
https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/CreatingHostedZone.html each domain needs a hosted zone. So we will wind up paying 0.10 per hosted zone or $1.2 per year . See SO thread
 
Standard Queries
  • $0.400 per million queries – first 1 Billion queries / month
  • $0.200 per million queries – over 1 Billion queries / month
Latency Based Routing Queries
  • $0.600 per million queries – first 1 Billion queries / month
  • $0.300 per million queries – over 1 Billion queries / month
Geo DNS and Geoproximity Queries
  • $0.700 per million queries – first 1 Billion queries / month
  • $0.350 per million queries – over 1 Billion queries / month
 
Queries are cached with TTL so not every request equals a query.
 
 
  • .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

 
Vapor seems to use West Virginia MySQL RDS only.. $10 cheaper than Aurora (Frankfurt Aurora vs RDS MySQL)… Even though on the Aurora page they said “It provides the security, availability, and reliability of commercial databases at 1/10th the cost”  That goes for commercial databases I guess.
 
Anyways, here the pricing as shown in Vapor CLI:
 
  • ‘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’,
 
 
Makes you wonder if you can choose region.. Perhaps you can as they say “~” plus price
 
Frankfurt table RDS MySQL
 
Standard Instances – Current Generation Single Availability Zone
 
  • 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
We could also do a reserved instance and that is sometimes cheaper than an on demand one. Especially if you pay up front. The same as with EC2 instances.

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
 
data transfer
  • 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
 
* $6 per month for $250 vs $5 at Digital Ocean, but they get cheaper as you grow.  DO is however only $0.0.2 per GB beyond the 250GB besides additional $0.0.1/GB for bandwidth . Seems Spaces is cheaper than Amazon S3. At leat for regular access to files. Only when you use Cloudfront Amazon goes down in data transfer fees and that we would be using as well for our CDN serving .

Amazon SQS Pricing

https://aws.amazon.com/sqs/pricing/

 
The first 1 million monthly requests are free (free tier only I believe). After that, the pricing is as follows for all regions:
 
  • 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)
 
Data Transfer IN
All data transfer in $0.00 per GB
Data Transfer OUT***
  • 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

 
Price per NAT gateway ($/hour) Price per GB data processed ($)
$0.052 $0.052 per Gb processed

Elasticache

Vapor allows you to use Redis Clusters for caching. Elasticache at Amazon offers Redis and Memcached Caching solutions. See  Vapor CLI file general use and memory optimized instances on offer. Here a list from Amazon (Frankfurt region again of course):
 
vCPUMem Gb
  • 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
 
Standard Cache Nodes – Current Generation Frankfurt
 
 

DynamoDB

If you do not use Redis Clusters Vapor automatically uses DynamoDB Caching. See article by Matt Stauffer.
 
  • 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

Pricing

 
Per Month per GB
  •  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

So what would we be paying per month for using our Laravel App
  •  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.

Jasper Frumau

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.