Professional Documents
Culture Documents
By Bhavin Turakhia
CEO, Directi
1
Agenda
2
Creative Commons Sharealike Attributions Noncommercial
Why is Scalability Important in a Web 2.0 world
3
Creative Commons Sharealike Attributions Noncommercial
The Variables
4
Creative Commons Sharealike Attributions Noncommercial
The Factors
• Platform selection
• Hardware
• Application Design
• Database/Datastore Structure and Architecture
• Deployment Architecture
• Storage Architecture
• Abuse prevention
• Monitoring mechanisms
• … and more
5
Creative Commons Sharealike Attributions Noncommercial
Lets Start …
6
Creative Commons Sharealike Attributions Noncommercial
Step 1 – Lets Start …
Appserver &
DBServer
7
Creative Commons Sharealike Attributions Noncommercial
Step 2 – Vertical Scaling
Appserver, CPU
DBServer
CPU
RAM RAM
8
Creative Commons Sharealike Attributions Noncommercial
Step 2 - Vertical Scaling
• Introduction
Increasing the hardware resources
without changing the number of nodes
Referred to as “Scaling up” the Server
• Advantages
Appserver, CPU CPU Simple to implement
DBServer
CPU CPU • Disadvantages
RAM RAM Finite limit
Hardware does not scale linearly
RAM RAM (diminishing returns for each
incremental unit)
Requires downtime
Increases Downtime Impact
Incremental costs increase
exponentially
9
Creative Commons Sharealike Attributions Noncommercial
Step 3 – Vertical Partitioning (Services)
• Introduction
Deploying each service on a separate node
• Positives
Increases per application Availability
AppServer
Task-based specialization, optimization and
tuning possible
Reduces context switching
DBServer
Simple to implement for out of band
processes
No changes to App required
Flexibility increases
• Negatives
Sub-optimal resource utilization
May not increase overall availability
Finite Scalability 10
Creative Commons Sharealike Attributions Noncommercial
Understanding Vertical Partitioning
11
Creative Commons Sharealike Attributions Noncommercial
Step 4 – Horizontal Scaling (App Server)
• Introduction
Increasing the number of nodes of
Load Balancer the App Server through Load
Balancing
Referred to as “Scaling out” the
AppServer AppServer AppServer App Server
DBServer
12
Creative Commons Sharealike Attributions Noncommercial
Understanding Horizontal Scaling
13
Creative Commons Sharealike Attributions Noncommercial
Load Balancer – Hardware vs Software
14
Creative Commons Sharealike Attributions Noncommercial
Load Balancer – Session Management
Observations
• Asymmetrical load distribution
(especially during downtimes)
Load Balancer
• Downtime Impact – Loss of
session data
15
Creative Commons Sharealike Attributions Noncommercial
Load Balancer – Session Management
16
Creative Commons Sharealike Attributions Noncommercial
Load Balancer – Session Management
• Clustered Session Clustered Session Management
Management
Easier to setup Load Balancer
No SPOF
Session reads are instantaneous
Session writes generate Network AppServer AppServer AppServer
I/O
Network I/O increases
exponentially with increase in
number of nodes
In very rare circumstances a
request may get stale session
data
• User request reaches subsequent
node faster than intra-node
message
• Intra-node communication fails
AKA Shared-nothing Cluster
17
Creative Commons Sharealike Attributions Noncommercial
Load Balancer – Session Management
18
Creative Commons Sharealike Attributions Noncommercial
Load Balancer – Session Management
• Recommendation
Use Clustered Session Management if you have –
• Smaller Number of App Servers
• Fewer Session writes
Use a Central Session Store elsewhere
Use sticky sessions only if you have to
19
Creative Commons Sharealike Attributions Noncommercial
Load Balancer – Removing SPOF
Active-Passive LB
• In a Load Balanced App Users
Server Cluster the LB is an
SPOF
• Setup LB in Active-Active or Load Balancer Load Balancer
Active-Passive mode
Note: Active-Active nevertheless AppServer AppServer AppServer
assumes that each LB is
independently able to take up
the load of the other Active-Active LB
If one wants ZERO downtime, Users
then Active-Active becomes truly
cost beneficial only if multiple
LBs (more than 3 to 4) are daisy Load Balancer Load Balancer
chained as Active-Active forming
an LB Cluster
AppServer AppServer AppServer
20
Creative Commons Sharealike Attributions Noncommercial
Step 4 – Horizontal Scaling (App Server)
21
Creative Commons Sharealike Attributions Noncommercial
Step 5 – Vertical Partitioning (Hardware)
• Introduction
Partitioning out the Storage
Load Balanced function using a SAN
App Servers
• SAN config options
Refer to “Demystifying Storage” at
http://wiki.directi.com -> Dev
University -> Presentations
DBServer • Positives
Allows “Scaling Up” the DB Server
SAN
Boosts Performance of DB Server
• Negatives
Increases Cost
22
Creative Commons Sharealike Attributions Noncommercial
Step 6 – Horizontal Scaling (DB)
• Introduction
Load Balanced
Increasing the number of DB nodes
App Servers Referred to as “Scaling out” the DB
Server
• Options
Shared nothing Cluster
Real Application Cluster (or Shared
DBServer DBServer DBServer
Storage Cluster)
SAN
23
Creative Commons Sharealike Attributions Noncommercial
Shared Nothing Cluster
24
Creative Commons Sharealike Attributions Noncommercial
Replication Considerations
• Master-Slave
Writes are sent to a single master which replicates the data to
multiple slave nodes
Replication maybe cascaded
Simple setup
No conflict management required
• Multi-Master
Writes can be sent to any of the multiple masters which replicate
them to other masters and slaves
Conflict Management required
Deadlocks possible if same data is simultaneously modified at
multiple places
25
Creative Commons Sharealike Attributions Noncommercial
Replication Considerations
• Asynchronous
Guaranteed, but out-of-band replication from Master to Slave
Master updates its own db and returns a response to client
Replication from Master to Slave takes place asynchronously
Faster response to a client
Slave data is marginally behind the Master
Requires modification to App to send critical reads and writes to
master, and load balance all other reads
• Synchronous
Guaranteed, in-band replication from Master to Slave
Master updates its own db, and confirms all slaves have updated
their db before returning a response to client
Slower response to a client
Slaves have the same data as the Master at all times
Requires modification to App to send writes to master and load
balance all reads
26
Creative Commons Sharealike Attributions Noncommercial
Replication Considerations
27
Creative Commons Sharealike Attributions Noncommercial
Real Application Cluster
replication
• Write your DAO layer to
ensure
writes are sent to a single DB
DBServer
reads are load balanced
Critical reads are sent to a DBServer DBServer
master
Writes & Critical Reads
Other Reads
29
Creative Commons Sharealike Attributions Noncommercial
Step 6 – Horizontal Scaling (DB)
DB DB DB
• Negatives
Finite limit
DB Cluster
SAN
30
Creative Commons Sharealike Attributions Noncommercial
Step 6 – Horizontal Scaling (DB)
31
Creative Commons Sharealike Attributions Noncommercial
Step 7 – Vertical / Horizontal Partitioning (DB)
• Introduction
Load Balanced
Increasing the number of DB
App Servers Clusters by dividing the data
• Options
Vertical Partitioning - Dividing
tables / columns
Horizontal Partitioning - Dividing by
DB DB DB
rows (value)
DB Cluster
SAN
32
Creative Commons Sharealike Attributions Noncommercial
Vertical Partitioning (DB)
33
Creative Commons Sharealike Attributions Noncommercial
Vertical Partitioning (DB)
• Negatives
One cannot perform SQL joins or
maintain referential integrity
(referential integrity is as such over- App Cluster
rated)
Finite Limit
DB Cluster 1 DB Cluster 2
Table 1 Table 3
Table 2 Table 4
34
Creative Commons Sharealike Attributions Noncommercial
Horizontal Partitioning (DB)
35
Creative Commons Sharealike Attributions Noncommercial
Horizontal Partitioning (DB)
• Techniques
FCFS
• 1st million users are stored on cluster 1 and the next on cluster 2
Round Robin
Least Used (Balanced)
• Each time a new user is added, a DB cluster with the least users is
chosen
Hash based
• A hashing function is used to determine the DB Cluster in which the
user data should be inserted
Value Based
• User ids 1 to 1 million stored in cluster 1 OR
• all users with names starting from A-M on cluster 1
Except for Hash and Value based all other techniques also
require an independent lookup map – mapping user to Database
Cluster
This map itself will be stored on a separate DB (which may
further need toCreative
be replicated)
Commons Sharealike Attributions Noncommercial
36
Step 7 – Vertical / Horizontal Partitioning (DB)
37
Creative Commons Sharealike Attributions Noncommercial
Step 8 – Separating Sets
DB DB DB DB DB DB DB DB DB DB DB DB
SAN SAN
39
Creative Commons Sharealike Attributions Noncommercial
Step 8 – Horizontal Partitioning (Sets)
40
Creative Commons Sharealike Attributions Noncommercial
Step 9 – Caching
41
Creative Commons Sharealike Attributions Noncommercial
Step 10 – HTTP Accelerator
42
Creative Commons Sharealike Attributions Noncommercial
Step 11 – Other cool stuff
• CDNs
• IP Anycasting
• Async Nonblocking IO (for all Network Servers)
• If possible - Async Nonblocking IO for disk
• Incorporate multi-layer caching strategy where required
L1 cache – in-process with App Server
L2 cache – across network boundary
L3 cache – on disk
• Grid computing
Java – GridGain
Erlang – natively built in
43
Creative Commons Sharealike Attributions Noncommercial
Platform Selection Considerations
45
Creative Commons Sharealike Attributions Noncommercial
Intelligent People. Uncommon Ideas.
Questions??
bhavin.t@directi.com
http://directi.com
http://careers.directi.com
46