Azure Cloud Patterns
-
Upload
tamir-dresher -
Category
Software
-
view
187 -
download
0
description
Transcript of Azure Cloud Patterns
![Page 1: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/1.jpg)
Azure Cloud Patterns
![Page 2: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/2.jpg)
About Me
• Software architect, consultant and instructor• Software Engineering Lecturer @ Ruppin Academic Center• Technology addict• .NET and Native Windows Programming
@[email protected]://www.TamirDresher.com.
![Page 3: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/3.jpg)
Cloud Patterns
http://en.wikipedia.org/wiki/List_of_cloud_types
![Page 4: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/4.jpg)
Agenda
• What are Cloud Patterns
• Queue Centric
• Poison Messages
• Retry Logic
• Circuit Breaker
• Cache Aside
![Page 5: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/5.jpg)
What are Cloud Patterns
• Architectural Patterns:“A design pattern in architecture and computer science is a formal way of documenting a solution to a design problem in a particular field of expertise”(http://en.wikipedia.org/wiki/Architectural_patterns)
![Page 6: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/6.jpg)
Meet The ProblemDevGeek Coffee Shop
![Page 7: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/7.jpg)
DevGeek Coffee Shop
• DevGeek Coffee is a well known and established coffee shop
• In business for 20 years
• Lately, with the increasing competition, sales are dropping
• Lets Help!
![Page 8: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/8.jpg)
DevGeek Coffee Shop - Operations
coffee
![Page 9: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/9.jpg)
DevGeek Coffee Shop - Operations
coffee#!$@
![Page 10: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/10.jpg)
What does this has to do with software?
• Cashier == Server
• Basically, this is a scalability issue
• Running in the cloud (potentially) makes scaling problem appear faster
![Page 11: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/11.jpg)
Scale Up
• Add More Resources to a Node
• Faster cashier– Better CPU to the server– More Memory
• Faster Coffee machine– Use a better algorithm/service
![Page 12: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/12.jpg)
Everything has a limit
MoneyMoneyCPUCPU
MEMMEMBANDWIDTHBANDWIDTH
StorageStorage
![Page 13: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/13.jpg)
Scale out
• Add More Nodes– More Cashiers
• Load Distribution– Round Robin– Performance– Other (location, expertise, etc)
![Page 14: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/14.jpg)
Azure Traffic Manager
![Page 15: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/15.jpg)
Meet The Problem 2DevGeek Coffee Shop
![Page 16: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/16.jpg)
DevGeek Coffee Shop – The clients complaints
• Long standing
• Sometimes orders gets lost
• Sometimes the line is so long that the workers close the doors
![Page 17: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/17.jpg)
DevGeek Coffee Shop – Latency and throughput
• Latency is a time interval between the stimulation and response– Time between ordering and receiving the coffee
• Throughput is the number of requests that can be served per unit time
![Page 18: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/18.jpg)
DevGeek Coffee Shop – Aroma model
coffee.
![Page 19: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/19.jpg)
Message Centric
Web Sites worker role::
worker roleweb role
![Page 20: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/20.jpg)
Message Centric – Load Leveling
::
Request Received at variable rate
Messages Processed at consistent rate
![Page 21: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/21.jpg)
Message Centric – Resilency
::
X
X
![Page 22: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/22.jpg)
Message Centric – Delayed Processing
::
![Page 23: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/23.jpg)
Azure Queuing Options
• Azure Storage Queues– Simple, Reliable, Persistent Queue– Max 200TB and 7 days TTL per message
• Azure Service Bus– Broader capabilities: publish/subscribe, remoting,
integration patterns– Max 80GB and unlimited TTL per message
http://msdn.microsoft.com/en-us/library/hh767287.aspx
![Page 24: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/24.jpg)
Azure Service Bus – Queueing
![Page 25: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/25.jpg)
Service Bus Messaging - Queue
• Two parts: 1.key/value properties2.binary message body.
• Example: a sales application sends message properties:
• *Seller="Ava" • *Amount=10000. • body : The sale's signed contract scanned image
![Page 26: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/26.jpg)
Producer ConsumerDemo
![Page 27: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/27.jpg)
C2
21
21
11
11
Removing Poison Messages
11
11
21
21334
0
40
Producers Consumers
30
30
2. GetMessage(Q, 30 s) msg 2
1. GetMessage(Q, 30 s) msg 1
11
11
21
21
10
10
20
20
P2
P1
C1
![Page 28: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/28.jpg)
C2
P2
P1
C1
Removing Poison Messages
340
40
Producers Consumers
11
11
21
21
2. GetMessage(Q, 30 s) msg 23. C2 consumed msg 24. DeleteMessage(Q, msg 2)7. GetMessage(Q, 30 s) msg 1
1. GetMessage(Q, 30 s) msg 15. C1 crashed
11
11
21
21
6. msg1 visible 30 s after Dequeue30
30
12
1211
1112
12
![Page 29: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/29.jpg)
C2
P2
P1
C1
Removing Poison Messages
340
40
Producers Consumers
12
12
2. Dequeue(Q, 30 sec) msg 23. C2 consumed msg 24. Delete(Q, msg 2)7. Dequeue(Q, 30 sec) msg 18. C2 crashed
1. Dequeue(Q, 30 sec) msg 15. C1 crashed10. C1 restarted11. Dequeue(Q, 30 sec) msg 112. DeliveryCount > 213. msg1.DeadLetter
12
12
6. msg1 visible 30s after Dequeue9. msg1 visible 30s after Dequeue
30
30
13
1312
1213
13
![Page 30: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/30.jpg)
Service Bus Messaging – Dead letters
• the name of the sub-queue is [queueName]/$DeadLetterQueue
• The path can be obtained using the FormatDeadLetterPath method of the QueueClient
• Can be consumed by any other consumer and check the messages, log them etc.
![Page 31: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/31.jpg)
Priority Queue
• The queue may hold message with different priorities (3-High, 1-Low)
Web Sites worker role::
worker roleweb role
:
![Page 32: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/32.jpg)
Priority Queue
Application
![Page 33: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/33.jpg)
Priority Queue
Application
![Page 34: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/34.jpg)
Meet The Problem 3DevGeek Coffee Shop
![Page 35: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/35.jpg)
DevGeek Coffee Shop – The clients complaints
1. Sometimes the soy milk ran out
2. the barista calls to the storeroom
3. The line is busy
4. The barista move to next order
5. Customer receive an order cancellation
![Page 36: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/36.jpg)
Transient Faults
• “Transient fault is a fault that is no longer present if power is disconnected for a short time and then restored.” (http://en.wikipedia.org/wiki/Transient_fault#Transient_fault)
• Many faults in connectivity to cloud are transient by nature
• Commonly occur when connecting to service or database
![Page 37: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/37.jpg)
Retry Pattern
• If at first you don’t succeed, try try again (William Edward Hickson)
• Retry Logic– Linear – every fixed amount of time– Exponential – if the server is heavy-used (throttling)
we don’t want to flood it immediate….1 sec….5 seconds….etc.
– Other
![Page 38: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/38.jpg)
Operation With Basic Retry int currentRetry = 0; while (currentRetry < MaxRetries) { try { // Calling external service. await TransientOperationAsync(); } catch (Exception ex) { currentRetry++; // Check if the exception thrown was a transient exception if (!IsTransient(ex)) { // If this is not a transient error // or we should not retry re-throw the exception. throw; } } await Task.Delay(TimeBetweenRetries); }
![Page 39: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/39.jpg)
Retry Pattern – Solutions
• Azure Storage IRetryPolicy
• Azure Service Bus RetryPolicy
IRetryPolicy noRetryPolicy = new NoRetry();BlobRequestOptions requestOptions = new BlobRequestOptions(){ RetryPolicy = noRetryPolicy,};
MessagingFactory factory = MessagingFactory.Create();factory.RetryPolicy = RetryExponential.Default; factory.RetryPolicy = RetryPolicy.NoRetry;
![Page 40: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/40.jpg)
The Transient Fault Handling Application Blockvar retryPolicy = new Incremental(5, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
retryPolicy.Retrying += (sender, args) => {Trace.WriteLine(args.LastException, "Information");
};
try { retryPolicy.ExecuteAction(() => {
TranisentErrorOperation(); });}catch (Exception) { // All the retries failed.}
http://msdn.microsoft.com/en-us/library/hh680934(v=pandp.50).aspx
![Page 41: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/41.jpg)
Circuit Breaker
![Page 42: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/42.jpg)
Retry Logic – Not Always Not all The time
• Baristas keeps retrying/failing – Time Consuming
• Maybe we can call someone else?
• The remote service still might get flooded
• If a failure is not transient, we wish that next attempts fail immediately
![Page 43: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/43.jpg)
Circuit Breaker
• Circuit Breaker pattern prevent repeatedly trying to execute an operation that is likely to fail
• continue without waiting for the fault to be rectified
• Prevents wasting valuable resources because of the wait
![Page 44: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/44.jpg)
Circuit Breaker
• The Circuit Breaker is a proxy
• Monitor the number of recent failures
• Decide if to proceed or do something else– Throw exception– Try different destination
![Page 45: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/45.jpg)
Circuit Breaker States
Closed Open
Success
Fail [threshold reached]
Half Open
Retry Timeout
Fail
Success
Fail [under threshold]
![Page 46: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/46.jpg)
Cache Aside
![Page 47: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/47.jpg)
Deja vu
• We fetch the same data
• We run the same calculation
• We query the same service
![Page 48: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/48.jpg)
Cache Aside
![Page 49: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/49.jpg)
Azure Caching
• Azure Managed Cache
• Azure Redis Cache
• In-Role Cache
![Page 50: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/50.jpg)
In Role Cache – co-located
![Page 51: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/51.jpg)
In Role Cache - Dedicated
![Page 52: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/52.jpg)
InRole Cache
![Page 53: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/53.jpg)
Summery
• What are Cloud Patterns
• Queue Centric
• Poison Messages
• Retry Logic
• Circuit Breaker
• Cache Aside
![Page 54: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/54.jpg)
References
• P&P Cloud Design Patterns - http://msdn.microsoft.com/en-us/library/dn568099.aspx
• http://cloudpatterns.org/• Cloud Architecture Patterns
![Page 55: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/55.jpg)
![Page 56: Azure Cloud Patterns](https://reader035.fdocuments.net/reader035/viewer/2022062319/554f3c6ab4c905471e8b4a9e/html5/thumbnails/56.jpg)
Images References
1. http://en.wikipedia.org/wiki/List_of_cloud_types
2. http://www.freedigitalphotos.net/images/Emotions_g96-Arms_Up_Character_Shows_Shock_And_Surprise_p142355.html
3. http://www.freedigitalphotos.net/images/Hot_drinks_g184-Coffee_In_White_Cup_p96634.html