1. Windows Azure Platform
Best Practices
Eric Nelson | ISV Application Architect | Microsoft UK
eric.nelson@microsoft.com | http://bit.ly/ericnelson | http://twitter.com/ericnel
Page 1
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 2
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 5
6. Vs traditional Windows development
It’s not really It’s not really
different. different.
There is just There is just
more of it less of it
Therefore many Windows Web development
best practices apply
Page 6
9. Instances of Role Types
“Typical Application” But…
Finance
Web
Message Finance
Web Web
Role A
Message Role A
Role A
Queue
Queue
10
Sec 10
Sec
Worker
Role A Worker Worker
Role A Role A
TIP: Queue writes are approx 20/s per writer
Page 9
10. Consolidation of Role Types
Scalable Message Passing Meta-Message Passing
HR Finance Sales HR Finance Sales
Message Message Message Message Message Message
Meta-queue
HR
HR Finance Sales
Finance
Queue Queue Queue
Sales
10 10 5 Finance
Sec Sec Sec 10
Sec
Worker Worker Worker Meta-worker Role
Role Role Role
Message Type?
TIP: Web Roles can communicate direct to Workers
TIP: Maximum time to process a Q Item is 2 hours
Page 10
11. Remember that SLA? Your instances will stop
Patching
React
Notification of • When an instance goes away, it’s
Moving instance gone, including its state!
lifecycle events
Failure
Page 11
13. Elasticity and Roles
From this
To this
Finance
Web Web Finance
Web Web Web
Message Role A
Role A Message Role A Role A
Role A
10 to 15
Queue
minutes Queue
10
Sec 10
Sec
Worker Worker
Worker Worker
Role A Role A
Role A Role A
Page 13
15. Latency
On premises application
App
Data
Service App
Request
Consistent and accepted latencies
Cloud based application
App
Service Data
App
Request
Increases in quantity and
variability of latencies
TIP: Expect Web Role to SQL Azure to take about twice as long
Page 15
16. Timeout
On premises application
Try to connect
Service
App App
Request
Data
Consistent, reliable
connectivity and access
Connection Yes Continue doing
Successful? work
Cloud based application
Timeouts? No
Service
App App
Request
Data
No
Tried 5 Yes
Increased likelihood
of timeouts
times? Fail
Page 16
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 17
21. Transactions & bandwidth
•Bandwidth
• Charged for usage
• Functionality that was not bandwidth Access Control
based may now be effected. Per AC transactions/month
• E.g. using Windows Azure Blobs
instead of writing to disk Bandwidth
Per GB transfer to/from datacenter
•Transactions
• Charged by quantity Storage
• Access types that were not Per GB stored & transactions
traditionally on a transaction count
may now be effected.
Service Bus
• E.g. using Access Control Services Per connection/month
and Storage
Page 21
22. Data center usage costing comparison
Web Role Web Role
Transaction Transaction
Browser Image Download Blob Browser Image Download Blob
Bandwidth Bandwidth
Egress Egress
Page 22
23. Batch Payloads
Frequent message Option 1:
passing with a small Serialized
amount of data can Message
Passing
# of ops
Header
effect performance and Header
Header
cost. Header
Header
Content
Content Content
Header Total Bytes
or Content
Overhead Content
Content Content Header
Message
Content
Structure Content
Header
Option 2;
Content
# of ops
TIP: Q items 8KB limit Packaged
Message Content
TIP: Watch out for data formats! Passing Content Total Bytes
TIP: Use storage APIs to group transactions
Page 23
24. Batch Queries
Single Query Use Batch Query Use
Query Worker Query
Role A
Query
Worker
Worker Query
Query Role
Role B Query
Worker
Query
Query Reduction of bandwidth
Role C
and transactions!
Query
Worker
Query Query
Role D
Query Worker
Role
Worker Query
Query Role E
Query
Page 24
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 25
26. Be aware of cost
140 million $140
Transactions per Month
120 million $120
Cost per Month
100 million $100
80 million $80
60 million $60
40 million $40
20 million $20
0
1 instance 5 instances
100 ms 100 ms
Instances polling storage
Page 26
27. Be aware of cost
140 million $140
Transactions per Month
120 million $120
Cost per Month
100 million $100
80 million $80
60 million $60
40 million $40
20 million $20
0
5 instances 5 instances
100 ms 1 second
Instances polling storage
Page 27
28. Be aware of cost
Be wary of frequent transactions with little work being done
140 million $140
Transactions per Month
120 million $120
Cost per Month
Unnecessary Cost
100 million $100
80 million $80
60 million $60
40 million $40
20 million $20
0
5 instances Polls which
100 ms found work
Instances polling storage
Page 28
29. Polling best practices
• Poll less often
• Synchronize polling with
business needs 8am to 12am til 4am
12pm – – every 1
every 100ms minute
4am til 8am – every
10 seconds
Page 29
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 32
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: SQL Azure has concurrency limits
TIP: You need SQL Server 2008 R2 Management Studio
TIP: Use Blob snapshots when you only need read access
TIP: For heavy read systems, distribute Blob reads across many workers
Page 33
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 34
35. Tables are funky
Entity: Shiny red Car
PK, RK, TS, att1, att2, att8
Entity: Blue Bird
PK, RK, TS, att1, att4
Entity: 2008 Tax Return
PK, RK, TS, att1, att2, att8, att9, att23, att46, att40
Page 35
36. Tables for storing Data
Why do this?
Partition Row Key Data Data Data Data
Key
Customer ID Description Name Credit Card # Order Total Tracking ID
1 Customer John Smith xxxx-xxxx-xxxx-xxxx
Partition A
1 Order – 1 £35.12 Z783lhs
1 Order – 2 £75.00 Z829bhb
2 Customer Bill Johnson xxxx-xxxx-xxxx-xxxx
Partition B
2 Order – 3 £10.00 Z778asd
2 Order – 4 £42.00 Z239uhy
3 Customer Travis Jones xxxx-xxxx-xxxx-xxxx
Partition C
3 Order – 5 £25.93 Z329nps
3 Order – 6 £80.94 Z440ydd
Page 36
37. Selecting keys is … key
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
TIP: Table deletes take time
TIP: Replicate data to avoid joins and increase indexes
Page 37
40. Sharding
Contact ID
Contact ID
First Name First Name
Cloud
Last Name
Last Name
Shipping Information
Shipping Information
Customer Credit Card #
Social Security #
Contact ID
Billing Data
Customer Credit Card # On Premise
Other Information
Social Security #
On Premise
Other Information
Page 40
41. Encryption
Contact ID
Contact ID
First Name First Name
Cloud
Last Name
Last Name
Shipping Information
Shipping Information £!”$&$%!&£%
Customer Credit Card # !£$&!%£&%*
Social Security # £”$&!%*^(&
Billing Data ^$”$&%$”&
On Premises
Other Information
On Premises
Page 41
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 43
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
eric.nelson@microsoft.com | http://bit.ly/ericnelson | http://twitter.com/ericnel
Page 44