Problem

This may happen everyday for transactional infrastructure:


Server 1
[Not supported by viewer]
Server 2
[Not supported by viewer]
PHP
PHP
Hmm...takes me a few 
hours to install all php lib 
synced with dev server.
[Not supported by viewer]
Thanks dude.
[Not supported by viewer]
Take a rest first, 
I will install my node stuffs later.

[Not supported by viewer]

Server is running out of RAM. 
Let me install php on spare server 
to serve some extra traffic.
[Not supported by viewer]

High traffic on php website
It's affecting my node service 
as well.

[Not supported by viewer]
Seems traffic is low now. 
Let me clean up the spare server. 
so sleepy...
[Not supported by viewer]
Just make sure you don't run 
"sudo rm -rf /" in server 1...
[Not supported by viewer]
Servers are arrived finally. 
<font style="font-size: 18px">Servers are arrived finally.&nbsp;</font>
Server 1
[Not supported by viewer]
Server 2
[Not supported by viewer]

Having a spare server should be better. 
That's why I bought 2 servers.
[Not supported by viewer]
Server 1
[Not supported by viewer]
Server 2
[Not supported by viewer]
PHP
PHP
Node
Node
Server 1
[Not supported by viewer]
Server 2
[Not supported by viewer]
PHP
PHP
Node
Node
PHP
PHP
Server 1
[Not supported by viewer]
Server 2
[Not supported by viewer]
PHP
PHP
Node
Node
PHP
PHP



To solve the issue mentioned above, here are some basic concepts I want to introduce.


Immutable

Immutable means the server is built as an image, and when it has issues or needs to upgrade to a new version, instead of fixing or updating it, we build a new server from scratch and fade out the old one.

Docker

Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.
Docker image packs any dependencies and source codes for any development programming language, and run it as container in any kind of host.
PHP 5.6.30Nginx 1.11.12composer.lockNode 6.9.5npm 3.10.10package.json


Docker host has CPU and memory resources to run docker containers, a group of docker hosts forms a resources pool (CPU and memory) to run containers. By pulling the docker image from docker registry to a new docker host, you don't need to install and compile lots of dependencies.
PHP 5.6.30Nginx 1.11.12composer.lockNode 6.9.5npm 3.10.10package.json
Docker Registry
[Not supported by viewer]
Nodejs Developer
[Not supported by viewer]
PHP Developer
[Not supported by viewer]


Rolling Deployment

When programmers commit the source code to git repository, a new immutable docker image with version tag will be built automatically and deployed to the docker cluster. Risk and downtime are reduced by running a copy of new version and remove the old ones from load balancer during deployment.
Github
[Not supported by viewer]
Docker Registry
[Not supported by viewer]
commit code (v1.1)
[Not supported by viewer]
trigger docker build
[Not supported by viewer]
CodeBuild
[Not supported by viewer]
push
[Not supported by viewer]
deploy
[Not supported by viewer]
EC2
[Not supported by viewer]
PHP (v1.0)
EC2
[Not supported by viewer]
PHP (v1.0)
EC2
[Not supported by viewer]
PHP (v1.0)PHP (v1.1)
EC2
[Not supported by viewer]
PHP (v1.0)
EC2
[Not supported by viewer]
PHP (v1.1)
PHP Programmers
<font style="font-size: 17px">PHP Programmers</font>


Cloud

When we want to build a server in the old days, we need to figure out a list for CPU, memory, hard disk size, etc. Beside the performance expectation for the server we also need to cater the compatibilities about those components for further upgrade. In cloud era, docker host is EC2 on AWS (Amazon Web Services, the most powerful cloud platform), and it can be launched via web console or command line very easily for any specified size of instance, which can still also be scaled horizontally or vertically.

Auto Scale Cluster

The number of EC2 in an auto scale cluster can be auto adjusted by overall CPU loading, CPU reservation percentage, and memory reservation percentage. You don't need to prepay numbers of EC2 for it, just pay what you have used.
Auto Scale Group
[Not supported by viewer]
EC2
EC2
EC2
EC2
Auto Scale Group
[Not supported by viewer]
EC2
EC2
EC2
EC2
EC2
EC2
EC2
EC2
EC2
EC2
EC2
EC2


Application Load Balancer

Route traffic directly to a service (groups of containers)
EC2
EC2
PHPPHP
EC2
EC2
PHPNodejs
immutable.cloud/php
[Not supported by viewer]
immutable.cloud/nodejs
[Not supported by viewer]


Auto Scale Service

A group of docker containers which the number of containers can be auto adjusted by service CPU loading and memory utilisation.
EC2
EC2
PHPPHP
EC2
EC2
PHPNodejs
EC2
EC2
PHPPHP
EC2
EC2
PHPNodejsPHPPHPPHP


Immutable Cloud

Combining all of the concepts mentioned above, it's immutable docker auto scale cluster.

Docker Auto Scale Cluster

You have a unlimited resources pool to run any kind of docker services with auto scale in both service level and cluster level.
This cluster can be server side to server any kind of backend programming for any kind of unexpected dynamic traffic, and it can also be client side for doing stress test or calculation tasks too.
It's the real power of the cloud!
EC2
EC2
NodejsPHP
EC2
EC2
PHP
EC2
EC2
NodejsPHPPHPPHP
...
[Not supported by viewer]
Auto Scale Group
<font style="font-size: 17px">Auto Scale Group</font>
RDS
[Not supported by viewer]
DynamoDB
[Not supported by viewer]
Redshift
[Not supported by viewer]
...
[Not supported by viewer]
Lambda
[Not supported by viewer]
Cloudwatch
[Not supported by viewer]
S3
[Not supported by viewer]
Users
[Not supported by viewer]
Application Load Balancer
<font style="font-size: 17px">Application Load Balancer</font>

Special Use Case Using Spot Instance

Spot EC2 instance is temporary instance in AWS cloud with much lower hourly price (most likely 80% off to the on demand EC2). Since it may be terminated anytime, it's highly recommended that all EC2 inside cluster should be identical (stateless). This money saving design is actually suitable for most of simple web servers.
EC2
EC2
NodejsPHP
EC2
EC2
PHP
EC2
EC2
PHPPHP
...
[Not supported by viewer]
 Auto Scale Group
(spot EC2 instance)
[Not supported by viewer]
NodejsPHPPHPNodejs

Problem Solved

With immutable cloud, it's just another happy day for programmers:
PHP
PHP
PHP
PHP
PHP
PHP
Docker Auto Scale Cluster
<font style="font-size: 13px">Docker Auto Scale Cluster</font>
Hey, I want to run 3 php containers with 1 core CPU and 1G RAM for each of them.

[Not supported by viewer]
No problems.

[Not supported by viewer]
Wait, I also need 1 nodejs container with 2 core CPU and 1G RAM...

[Not supported by viewer]
PHP
PHP
PHP
PHP
PHP
PHP
Node
Node
Docker Auto Scale Cluster
<font style="font-size: 13px">Docker Auto Scale Cluster</font>
Not enough resources, but no worries, I will enlarge the resource pool.

[Not supported by viewer]
Oh, a new online ad is launched and php website is facing high traffic!

[Not supported by viewer]
PHP
PHP
PHP
PHP
PHP
PHP
Node
Node
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
Docker Auto Scale Cluster
<font style="font-size: 13px">Docker Auto Scale Cluster</font>
Easy, let me auto scale out the PHP service.

[Not supported by viewer]
PHP
PHP
PHP
PHP
Node
Node
Docker Auto Scale Cluster
<font style="font-size: 13px">Docker Auto Scale Cluster</font>
..zzZZ
[Not supported by viewer]
..zzZZ
[Not supported by viewer]
Traffic is low at night, let me auto scale in to save some hosting cost. 
Have a nice dream.

[Not supported by viewer]

Cool!
[Not supported by viewer]