windows azure platform best practices by ericnel
DESCRIPTION
50minute discussion of best practices for Windows Azure Platform delivered at DevCon London, Sept 2010TRANSCRIPT
Page 1
Eric Nelson | ISV Application Architect | Microsoft UK
[email protected] | http://bit.ly/ericnelson | http://twitter.com/ericnel
Windows Azure Platform
Best Practices
Page 2
Assumption
• You already have familiarity with the Windows
Azure Platform
• If you don’t then you will still learn stuff
– But you will be missing some context. Sorry
Page 3
Agenda Overview
• Role Instances
• Latency & timeouts
• Transactions & bandwidth
• Data/state
• Data sensitivity
Summary
Page 4
Overview
Page 5
Windows Azure Platform
makes it easy and cost effective
to run your applications
and store your data
inside Microsoft Data Centres
using existing skills
and integrate with
your existing on-premise applications
Page 6
Vs traditional Windows development
It’s not really
different.
There is just
more of it
It’s not really
different.
There is just
less of it
Therefore many Windows Web development
best practices apply
Page 7
Agenda Overview
• Role Instances
• Latency & timeouts
• Transactions & bandwidth
• Data/state
• Data sensitivity
Summary
Page 8
Role Instances
Page 9
Instances of Role Types
Finance
Message
“Typical Application”
Queue
10
Sec
Worker
Role A
Web
Role A
Queue
Finance
Message
10
Sec
Worker
Role A
Web
Role A
Worker
Role A
Web
Role A
But…
TIP: Queue writes are approx 20/s per writer
Page 10
Consolidation of Role Types
HR
Queue
Finance
Queue
Sales
Queue
HR
Message Finance
Message
Sales
Message
10
Sec
10
Sec
5
Sec
Scalable Message Passing
Worker
Role Worker
Role
Worker
Role
HR
Message
Finance
Message Sales
Message
Meta-queue
HR
Finance
Sales
Finance
10
Sec
Message Type?
Meta-worker Role
Meta-Message Passing
TIP: Web Roles can communicate direct to Workers
TIP: Maximum time to process a Q Item is 2 hours
Page 11
Remember that SLA? Your instances will stop
React
• When an instance goes away, it’s
gone, including its state!
Patching
Moving
Failure
Notification of
instance
lifecycle events
Page 12
Role instance management example
Page 13
Elasticity and Roles
Queue
Finance
Message
10
Sec
Worker
Role A
Web
Role A
Worker
Role A
Web
Role A
From this
Queue
Finance
Message
10
Sec
Worker
Role A
Web
Role A
Worker
Role A
Web
Role A
To this
Web
Role A
10 to 15
minutes
Page 14
Latency and Timeouts
Page 15
Latency
Service
Request
App
Data
App
Consistent and accepted latencies
On premises application
Service
Request
App
Data App
Increases in quantity and
variability of latencies
Cloud based application
TIP: Expect Web Role to SQL Azure to take about twice as long
Page 16
Timeout
Service
Request App
Data
Timeouts?
App
Increased likelihood
of timeouts
Cloud based application
Service
Request App
Data App
Consistent, reliable
connectivity and access
On premises application
Yes
No
Yes
No Tried 5 times?
Connection Successful?
Try to connect
Continue doing
work
Fail
Page 17
SQL Azure – you must use retries!
• Transient network issues
– Loss of connection
• The Fabric may auto-magically reconnect your
session to a replica of your data
– Some result in termination of client session
• Throttling
– Excessive resource usage, long running transactions
– Can lead to
• Termination of client session
• Temporary inability to establish a new connection
Page 18
Timeout Retry Code Example
Page 19
Timeout Retry Code Example
TIP: There is a new code library for all this!
Page 20
Transactions & bandwidth
Page 21
Transactions & bandwidth
Access Control Per AC transactions/month
Service Bus Per connection/month
Bandwidth Per GB transfer to/from datacenter
Storage Per GB stored & transactions
•Bandwidth • Charged for usage
• Functionality that was not bandwidth
based may now be effected.
• E.g. using Windows Azure Blobs
instead of writing to disk
•Transactions • Charged by quantity
• Access types that were not
traditionally on a transaction count
may now be effected.
• E.g. using Access Control Services
and Storage
Page 22
Web Role
Blob Image Download Browser Bandwidth
Egress
Transaction
Web Role
Blob Image Download Browser Bandwidth
Egress
Transaction
Data center usage costing comparison
Page 23
Header
or
Overhead
Content
Message
Structure
Content
Content
Content
Batch Payloads
Frequent message
passing with a small
amount of data can
effect performance and
cost.
Content
Header Header
Header Header
Content
Head
er
Option 1:
Serialized
Message
Passing
Total Bytes
Co
nte
nt
# o
f o
ps
Header
Content
Content
Content
Option 2;
Packaged
Message
Passing
Head
er
Co
nte
nt
Content Total Bytes
# o
f o
ps
TIP: Use storage APIs to group transactions
TIP: Watch out for data formats!
TIP: Q items 8KB limit
Page 24
Single Query Use
Batch Queries
Query
Query
Query
Query
Query
Worker
Role A
Worker
Role B
Worker
Role C
Worker
Role D
Worker
Role E
Batch Query Use
Reduction of bandwidth
and transactions!
Query
Query
Query
Query
Query
Query
Query
Query
Query
Query
Worker
Role
Worker
Role
Page 25
Be aware of “new costs” e.g. polling
• Consider introducing polling a queue every 100ms
• 25,920,000 polls/month
• £0.0061 per 10,000 storage transactions
• Therefore it will cost – £15.81/month
• To get an SLA, need two worker roles polling – £31.62/month
• Cost of two workers – £0.0728 per hour x 720 x 2
– £104.83/month
• Total cost £136.45/month
TIP: Yet a 1GB SQL Azure will cost you £6/month
Page 26
Instances polling storage
0
140 million
120 million
100 million
80 million
60 million
40 million
20 million
1 instance
100 ms
5 instances
100 ms
$140
$120
$100
$80
$60
$40
$20
Co
st p
er
Mo
nth
Be aware of cost
Tran
sact
ion
s p
er
Mo
nth
Page 27
Instances polling storage
0
140 million
120 million
100 million
80 million
60 million
40 million
20 million
5 instances
100 ms
5 instances
1 second
$140
$120
$100
$80
$60
$40
$20
Co
st p
er
Mo
nth
Be aware of cost
Tran
sact
ion
s p
er
Mo
nth
Page 28
Be wary of frequent transactions with little work being done
Instances polling storage
0
140 million
120 million
100 million
80 million
60 million
40 million
20 million
Tran
sact
ion
s p
er
Mo
nth
$140
$120
$100
$80
$60
$40
$20
Polls which
found work U
nn
ecess
ary
Co
st
Be aware of cost
Co
st p
er
Mo
nth
5 instances
100 ms
Page 29
• Poll less often
• Synchronize polling with
business needs
Polling best practices
12am til 4am
– every 1
minute
4am til 8am – every
10 seconds
8am to
12pm –
every 100ms
Page 30
HR
Message
Finance
Message Sales
Message
Polling best practices cont.
HR
Queue
Finance
Queue
Sales
Queue
HR
Message Finance
Message
Sales
Message
10
Sec
10
Sec
5
Sec
Meta-queue
HR
Finance
Sales
Finance
10
Sec
Message Type?
Meta-worker Role
Scalable Message Passing Meta-Message Passing
Worker
Role Worker
Role
Worker
Role
Page 31
Data/State
Page 32
Data/State
• Windows Azure instances are highly dynamic
– Role instance local data is volatile
• Instances are independent
– State changes are not reflected in other instances
• Therefore
– Local instance storage is only useful for temporary
data or as a cache
– All other data needs to be moved to durable storage
Page 33
Durable forms of storage in Windows Azure
• Windows Azure Storage
– Blobs
• Page – random read/writes
• Block – streaming
• Drive – legacy
– Queues
– Tables
• SQL Azure Database
– Tables
TIP: For heavy read systems, distribute Blob reads across many workers
TIP: Use Blob snapshots when you only need read access
TIP: SQL Azure has concurrency limits
TIP: You need SQL Server 2008 R2 Management Studio
Page 34
Example: Registry/Configuration/User Settings
Commonly this is stored in the registry, xml or ini files.
Options Best Case Usage
Blob storage Configuration file that is read
only once during app load
SQL database Used in environments where a
SQL database already exists
Windows Azure table User settings that may be
changed externally from the
environment
Page 35
Tables are funky
Entity: Shiny red Car
PK, RK, TS, att1, att2, att8
Entity: 2008 Tax Return
PK, RK, TS, att1, att2, att8, att9, att23, att46, att40
Entity: Blue Bird
PK, RK, TS, att1, att4
Page 36
Tables for storing Data
Why do this?
Partition
Key
Row Key Data Data Data Data
Customer ID Description Name Credit Card # Order Total Tracking ID
1 Customer John Smith xxxx-xxxx-xxxx-xxxx
1 Order – 1 £35.12 Z783lhs
1 Order – 2 £75.00 Z829bhb
2 Customer Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order – 3 £10.00 Z778asd
2 Order – 4 £42.00 Z239uhy
3 Customer Travis Jones xxxx-xxxx-xxxx-xxxx
3 Order – 5 £25.93 Z329nps
3 Order – 6 £80.94 Z440ydd
Part
itio
n A
Part
itio
n C
Part
itio
n B
Page 37
Consider searching an address book
Search By Partition Key Row Key
Name Last name + First initial First name + Middle initial
Phone number Area code Number
Address County + city House number + Street
name
Selecting keys is … key
TIP: Replicate data to avoid joins and increase indexes
TIP: Table deletes take time
Page 38
Data Sensitivity
Page 39
Purchasing
Database Product
catalogue
Secure Transaction
(Service Bus)
Segmentation
Online Shop Online Shop
Product
catalogue
Page 40
Customer Credit Card #
Shipping Information
Last Name
First Name
Contact ID
Social Security #
Billing Data
Other Information
On Premise
Contact ID
Social Security #
Customer Credit Card #
Other Information
Shipping Information
Last Name
First Name
Contact ID
On Premise
Cloud
Sharding
Page 41
Customer Credit Card #
Shipping Information
Last Name
First Name
Contact ID
Social Security #
Billing Data
Other Information
On Premises
£!”$&$%!&£%
£”$&!%*^(&
!£$&!%£&%*
^$”$&%$”&
Shipping Information
Last Name
First Name
Contact ID
On Premises
Cloud
Encryption
Page 42
Agenda Overview
• Role Instances
• Latency & timeouts
• Transactions & bandwidth
• Data/state
• Data sensitivity
Summary
Page 43
Summary
• Windows Web Development best practices apply
• But
• Cost becomes surprisingly significant in shaping
architectures
• Plenty of early adopters, therefore
– Good best practice are now appearing
– Plenty of detail to dig into
Page 44
NEXT STEPS
For latest slides and all the links http://bit.ly/ericnelson
For more resources and information http://bit.ly/startazure
As an ISV intending to explore/adopt azure, sign up to http://bit.ly/ukmpr
and come along and meet with us http://blogs.msdn.com/b/ukisvdev
Eric Nelson | ISV Application Architect | Microsoft UK [email protected] | http://bit.ly/ericnelson | http://twitter.com/ericnel