Professional Documents
Culture Documents
Contents
1.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
8
8
9
11
13
14
17
19
Youve been putting off this moment for months, but now is the time to
make a decision. Your app wont make you any money just by sitting on
your laptop, you need a way to put it in front of your customers, and this
means that you have to host it somewhere.
Youre not looking for a place to host a 3-pages sales brochure, but for
something that can accommodate the unique needs of your app. You
know that hosting will be a line on your expenses sheet each month, a
line that you will never get away with.
Until now, youve been thinking that a couple of hours worth of Googling
will get you enough information to make a decision. But right after the
first 15 minutes you realize that this is an uphill battle:
theres the jargon: shared, VPS, dedicated server, cloud, PaaS, IaaS,
At least the features of the various offers look quite similar (1GB of
RAM is the same everywhere, isnt it?) and youre thinking that a quick
spreadsheets will help you decide Wait, whats this managed hosting
thing? So, theres such a thing as unmanaged? And how can you figure
out whats right for you?
how to decide what kind of hosting is the best for your app
how to estimate hosting costs
how to compare hosting offers
how to master the hosting industry jargon
Thats where our model app comes in: with a simple DNS change, our
customer can make our app serve all of the product images, and with
another simple change to the URL structure our app will also serve
resized images, taking all the load out of the customers infrastructure.
Our model app will have those major logical components:
web server
application server
database server
file storage
The web server is the entry point of our system: for an already resized
image, it simply returns the file as stored on our file storage system, for
a new image it forwards the request to the application server and waits
for the resized version to be available in the file storage. The application
server performs the actual image resizing and stores the data in file
storage and the metadata in the database (such as how many resized
versions exist for the original image and how many images have been
resized for each customer in a given period).
Our customers use an administration interface to upload their own
images and to configure settings such as the quality of the resized
images and the allowed sizes; our application stores these settings in
the database.
Heres the simplest possible logical diagram of our model app:
You could choose almost any technology stack to build this model app.
If I were to build such an app Id go with the stack I know better, which
for me is:
web server: nginx
application server: Java
database server: PostgreSQL
much money and effort you can dedicate to it, but at the very minimum
aim for 2x redundancy at each level of the stack.
https://www.webfaction.com
10
You dont have to worry about the hardware details, because the hosting
company will replace a failing disk drive or network card. Thanks to
fierce competition, buying a low-end VPS from a reputable, established
company costs around $5 per month, and many of those companies also
offer hourly billing for temporary surges in traffic and quick experimentations.
Some companies offering VPS:
Digital Ocean2
Vultr3
Linode4
You can usually get more performance out of a VPS by asking for
more CPU, RAM or disk space (scaling up) and paying an increased
fee. Resizing down is a little more difficult and not always possible: for
example, to scale down at Digital Ocean you would have to purchase a
second, smaller VPS, migrate everything over and shut down the original
VPS, thus getting a new IP address and suffering the DNS propagation
delays.
For most web applications a VPS is flexible enough to accommodate
custom binaries and particular configurations; depending on the hosting
company and on the VPS plan you choose, you may never need to move
to dedicated servers and just order more CPU and memory to respond
to increased traffic.
On a VPS youre still sharing some hardware resources: the network, the
I/O bandwidth and the CPU: if your VPS demands too much of any
of those resources, the hosting company may force you to move to a
higher plan or in the extreme case kick you out altogether. From time
to time you may see the other side of this problem: your app shows a
performance degradation without an apparent cause. This is the effect
2
https://www.digitalocean.com
https://www.vultr.com
4
https://www.linode.com
11
Do not spend more than $50/month on any single VPS: at this price
point, a dedicated server is a much better value for money.
12
Hetzner5
OVH6
LeaseWeb7
SoftLayer8
https://www.hetzner.de/en
https://www.ovh.com
7
https://www.leaseweb.com
8
http://www.softlayer.com
13
2.4 Colocation
You buy your own machines, then send them to a datacenter which
provides power and connectivity. This is almost like renting dedicated
servers, except that the machines are your property and fall under your
responsibility: when some hardware component breaks, you travel to the
datacenter and replace it, or you have a datacenter technician replace it
with the spare part that you had sent originally along with the servers.
The main factors for colocation pricing are:
the height that your servers will occupy in the rack, measured in
units (a 1U server will cost less than a 2U or 4U server)
the power that your servers will draw
the bandwidth
My advice: you should buy and colocate machines only when
your business is well established and can afford the capital
expense. Over a lifespan of 2-3 years colocation can be cheaper
than renting dedicated servers, even if you factor in the hardware replacements and the labor.
14
2.5 Cloud
There are as many definitions of cloud as there are hosting companies
out there. I will limit the discussion to the IaaS (Infrastructure as a
Service) variant, where you rent some computing resources (CPU, RAM,
storage, network) from a hosting company: in general those computing
resources come in the form of virtual machines, similar to a VPS. Some
companies exploit this similarity to define their services as cloud servers
where in reality they simply offer VPS with hourly billing.
Lets define what we want from a cloud hosting solution:
billing by the hour (or by the minute) of the VM and the other
resources (storage, network services)
ability to obtain more resources in minutes
ability to resize up and down the existing VM
networked storage for the VM volumes
network load balancers and firewalls are available as a service
Some companies offering cloud hosting:
Amazon AWS9
Google Cloud Platform10
Microsoft Azure11
Dediserve12
ProfitBricks13
LunaCloud14
SoftLayer15
https://aws.amazon.com
https://cloud.google.com
11
http://azure.microsoft.com
12
http://www.dediserve.com
13
https://www.profitbricks.com
14
http://www.lunacloud.com
15
http://www.softlayer.com
10
15
With a cloud server you get root access and you can install your own
software. Thats about the extent of the similarities between cloud
providers, because each one has a particular service model:
some providers offer a predefined set of virtual machine configurations and you cannot add memory without also having to buy more
CPU capacity; other providers let you mix and match resources, so
you may have a virtual machine with 8 CPU cores but only 512MB
of RAM
some providers dont install the stock version of a operating system, but a special version that they have customized to better
work in their own environment (Amazon calls this an AMI - Amazon
Machine Image)
your virtual machines may come with a local disk and networked
storage is offered as an option, or there may be only networked
storage and no local disk at all
the data you store on a local disk may not necessarily conserved
after your virtual machine reboots
The list of differences grows each day, and with cloud providers introducing new features at a regular (and fast!) pace is almost impossible to
say that one provider is better than another one.
The only way to compare cloud providers is to focus on your
particular use case and try to come up with realistic, if pessimistic, estimates about your traffic and your apps usage of
computing resources.
Cloud providers also give you lot of additional services, like:
object storage: store files using a web services interface
block storage: persistent networked storage that you can mount on
your virtual machines like a filesystem
16
network load balancers: distribute traffic across the various instances of your app
One aspect of cloud providers of great interest to us is that pricing is
based on usage, so the more resources you use the higher your bill will be.
You may very well pay $10 the first month and $1000 the second month.
What passes as usage depends on the particular cloud provider and
technology: for example, Amazon AWS has a block storage offering (EBS)
which is billed according not only to how much space you provision,
but also to how many I/O operations occur: good luck coming up with
a realistic estimate for it, especially when AWS itself says you may see
a different number of I/O requests on your bill than is seen by your
application 16 .
Since cloud pricing is very difficult to predict because of its own nature,
it is very important that you keep a very close watch on usage and set
up billing alerts to make sure you stay on top of hosting expenses.
Cloud hosting comes with some constraints that propagate up to the
design and development techniques: 2 instances of your app on different
VMs may suddenly no longer communicate, because one of the 2 has
been stopped for a failure of the underlying hardware node or for
a network misconfiguration. You can often achieve this resiliency by
taking advantage of the various services offered by the cloud, such as
message queues, distributed object storage or databases that automatically replicate. Keeping those constraints in mind is useful regardless of
your hosting environment, because they encourage you to think about
loose coupling of architecture components and thus producing more
robust software.
You should also keep in mind that a cloud-based hosting solution has
failure modes that you cannot really anticipate, and even the cloud
providers sometimes have troubles mastering their own creations. For
example, AWS had one notable failure in October 2012 17 related to the
EBS product which propagated to several other component: the Elastic
16
17
17
2.6 PaaS
PaaS stands for Platform as a Service: you get to run your code on an
application, rather than directly on an infrastructure. Your code has to
obey the various conventions and rules set by the application platform,
you use some specific PaaS tools to deploy your code and in general
you dont have access to the underlying computing resources. On a PaaS
you cannot install custom software, for example a specific version of
HAProxy, but for an additional fee you can choose some add-ons in a
list pre-configured by the platform. Since you dont get direct access
to the operating system, you cannot optimize the kernel settings, nor
the storage configuration of your database: the assumption is that the
provided configuration works well enough for the kind of applications
that the PaaS supports.
18
https://www.heroku.com
http://aws.amazon.com/elasticbeanstalk/
20
https://www.engineyard.com/
19
19