2. Today we are looking at:
•Tier architecture and cloud computing
•Moving from 3-tier to n-tier
•Scaling services up for use in Enterprise web
•Caches
•Proxies
•Load Balancing
•Queueing
4. Presentation
Logic
Business Logic
Data Access
Logic
Database
1 tier architecture
• All 3 layers are kept on the same machine
• Presentation, logic, and data are highly connected
• Bad for scalability (single processor being used
• Bad for portability
• Bad for maintenance (change one thing…change them all)
5. Presentation
Logic
Business Logic
Data Access
Logic
Database
2 tier architecture
Client Server
• Database runs on server
• Easy if you want to switch to a new database
• Presentation and logic still tightly connected
• Bad for server load
• Bad if you want to make changes
11. Easier to maintain
Components are reusable
Faster division of work
Web Designer does presentation
Software Engineer does logic
DB Man does DB things…
22. Server Storage
Upload Image
Files written
to storage
Request Image
Client Computer
Image Located
Image Sent
make functions to separate services in
order to aid in scalability
26. Image
Write
Service
Storage
Upload Image
Files written
to storage
Request Image
Client Computer
Image Located
Image Sent
Image
retrieval
service
Backup
Storage
Located in
another
geographical
location
Think about options to deal with extra
large data sets
27. Image
Write
Service
Storage
Upload Image
Files written
to storage
Request Image
Client Computer
Image Located
Image Sent
Image
retrieval
service
Backup
Storage
Located in
another
geographical
location
horizontal and vertical scaling
Horizontal
Vertical
Adds more storage /
processing power etc. to the
same server
Adds more nodes/shards (this
is the preferred option for big web
services)
28. Image Write
Service
Storage
Upload Image Files written
to storage
Request Image
Client Computer
Image Located
Image Sent
Image
retrieval
service
Backup
Storage
Located in
another
geographical
location
Image Write
Service
Storage
Backup
Storage
Image
retrieval
service
29. Image Write
Service
Storage
Upload Image Files written
to storage
Request Image
Client Computer
Image Located
Image Sent
Image
retrieval
service
Backup
Storage
Located in
another
geographical
location
Image Write
Service
Storage
Backup
Storage
Image
retrieval
service
30. Services
Separate key web services into different
logic nodes
Redundancy
Make sure that there is backup of all
data
Partitions
Split everything into different partitions/
shards to deal with increasing data
usage
38. Application
Server Database
server
I would like an image of a dog
• Use a cache to store things that are sorted for most
recently
• There’s a good chance that if something is searched
for once, it is going to be searched for again
cache
Cache is checked before
going to the DB server
39. Application
Server Database
server
I would like an image of a dog
• This tiny change makes a big difference to application
speed!
• Cache reads are lightning fast
• Database server reads are snails pace in comparison
cache
Cache is checked before
going to the DB server
41. Database
server
Application
Server
cache
I would like an
image of a
dog
Each request that is made passes through a
cache, if it has the data it returns it, if not it goes to
the database
Global cache system I
Application
Server
Application
Server
Application
Server
This is the most common type of cache system
42. Database
server
Application
Server
cache
I would like an
image of a
dog
Application server checks the cache, if it doesn't
find what it is after the application server then
goes to the database
Global cache system II
Application
Server
Application
Server
Application
Server
Better for large files that may otherwise clog the
cache. Also better for static cache files
43. Want to give it a go?
http://memcached.org/
http://www.phpfastcache.com/
(documentation is online)
Caches
46. Database
server
I would like
an image of a
cat
I would like
an image of a
cat
I would like
an image of a
cat
I would like
an image of a
cat
Application
Server
Application
Server
Application
Server
Application
Server
Proxy
Proxies are good
when lots of people
are searching for
the same thing
Collapses requests
into a single
request, reduces
database reads
Bring me the
cats!
47. Database
server
I would like
an image of a
black cat
I would like
an image of a
ginger cat
I would like
an image of a
tabby cat
I would like
an image of a
fluffy cat
Application
Server
Application
Server
Application
Server
Application
Server
Proxy
Also good if people
are searching for
close to the same
thing
Bring me the
cats!
48. Database
server
I would like
an image of a
black cat
I would like
an image of a
ginger cat
I would like
an image of a
tabby cat
I would like
an image of a
fluffy cat
Application
Server
Application
Server
Application
Server
Application
Server
Proxycache
We can use techniques at
the same time to make it
even faster.
A lot of proxies actually
come with a cache built into
them
49. Want to give it a go?
http://www.squid-cache.org/
https://www.varnish-cache.org/
(documentation is online)
proxy/cache
50. scaling services up for use
in an enterprise level web
program
load
balancing
51. Database
server
I would like
an image of a
black cat
I would like
an image of a
ginger cat
I would like
an image of a
tabby cat
I would like
an image of a
fluffy cat
Application
Server
Application
Server
Application
Server
Application
Server
Magic Box
!?!?
!?!?
52. I would like
an image of a
black cat
upload a
picture of a
ginger cat
I want to
change my
password
I just really
like cats
Application
Server
Application
Server
Application
Server
Application
Server
Load
Balancer
53. I would like
an image of a
black cat
upload a
picture of a
ginger cat
I want to
change my
password
I just really
like cats
Application
Server
Application
Server
Application
Server
Application
Server
Load
Balancer
Load
Balancer B
54. I would like
an image of a
black cat
upload a
picture of a
ginger cat
I want to
change my
password
I just really
like cats
Application
Server
Application
Server
Application
Server
Application
Server
Load
Balancer
Load balancing methods
round robin
Random node
As it sounds…just picks a random node
Node with most free processing power
Node with access to [x]
Criteria based
Location based
node[x], node[x+1], node[x+2]
Node in Aberdeen
Node in Dundee
55. Problems with load balancing
Managing user session data
You don’t want to be put to a different server node
every time you change a page
Even changing a node every time you visit a site
would be a pain! (shopping basket might be
deleted)
56. Want to give it a go?
http://www.haproxy.org/
(documentation is online)
load balancing
62. Want to give it a go?
http://zookeeper.apache.org/
http://www.rabbitmq.com/
(documentation is online)
queues
63. Recap
•Tier architecture and cloud computing
•Moving from 3-tier to n-tier
•Scaling services up for use in Enterprise web
•Caches
•Proxies
•Load Balancing
•Queueing