introduction to distributed architecture
TRANSCRIPT
Distributed Architecture
Introduction to
What is Architecture? A software architecture is an abstract view of a software system distinct from the details of implementation, algorithms, and data representation.
SEI @ Carnegie Mellon
Why Architecture Matters
Accidental Architecture
Every… system has an architecture. While some of these architectures are intentional, most appear to be accidental
Grady Booch
Requirements Analysis
Design
Code and Test
Integration
System Test
Waterfall Process
Requirements Analysis
Design
Code and Test
Integration
System Test
Waterfall Process
Analysis Paralysis
MassiveIntegration
Design divorced from reality
Manifesto for Agile Software Development
We are uncovering better ways of developingsoftware by doing it and helping others do it.Through this work we have come to value:
Individuals and interactions over processes and toolsWorking software over comprehensive documentationCustomer collaboration over contract negotiationResponding to change over following a plan
That is, while there is value in the items onthe right, we value the items on the left more.
Scrum: An agile Process
Architect Code
Techies crave Extremes
Functional requirementsWhat the system should do.• Use cases, User stories, acceptance criteria• Defines passing QA• Day to day you focus on this
Nonfunctional requirementsWhat the system should be.• Extremely expensive or impossible to “fix”
later on• Defined passing Production• Assumed by your customers and users
Nonfunctional Requirements• Availability• Stability• Efficiency• Reliability• Maintainability• Extensibility
• Fault Tolerance• Security• Capacity• Latency• Flexibility• Scalability
Functional: Passed QABeautiful site (in my opinion)Easy to use
Nonfunctional: Failed ProductionAvailability StabilityLatency CapacityThroughput
ArchitectureThere is no best architecture
Pacemakers and Guided Missiles
The Flying Buttress
Patterns
Example: Layered Architecture
Three Tier ArchitectureThe classic 3 tier architecture
N-Tier ArchitectureBecause three tiers wasn’t enough!
N-Tier Architecture
SHAREPOINT
BIZTALK
SQL SERVER
Windows Server 2008
SMS
License managementIIS
Questions about Architecture?
Distributed ArchitectureDesigns appropriate for small brochureware websites fail outrageously when applied to thousand-user, transactional, distributed systems...
Michael T. Nygard
Key Constraints on Distributed Systems
• Stability • Reliability and fault tolerance• Consistency• Capacity and Scalability• Security
Scenario: StabilityYou are the lead developer on a national health care site that will register millions of users a week. You are responsible for the signup process.
Your team must verify the identity of users with a third party API. You call the service and the third party system will return a boolean true if the identity is valid or false otherwise.
private string Register(RegistrationInfo registrationInfo) { try { bool validIdentity = identityService.verifyIdentity(registrationInfo);
if (validIdentity) { database.save(registrationInfo); return “register_success.htm"; }
return “register_failure.htm"; } catch (Exception) { return "errorpage.htm"; }
}
6. RegisteredIdentity
Verification
Database
2. Verify
3. VerifiedSite Server
Stability
4. Save User5. User Saved
1. Register
6. RegisteredIdentity
Verification
Database
2. Verify
3. VerifiedSite Server
Unbalanced Capacities
4. Save User5. User Saved
1. Register
Identity Verification
Blocked Threads
Site ServerVerify sally
Verify bob
joe verified
Verify joe
Verify sally
Verify joe
Verify bobVerify bob
Verify bob
Verify bob
Verify bob
joe verified
Cascading Failures
Site Server
Site Server
Site Server
Site Server
private string Register(RegistrationInfo registrationInfo) { try {
identityService.Timeout = 10000; bool validIdentity = identityService.verifyIdentity(registrationInfo);
if (verified) { db.save(registrationInfo); return “register_success.htm"; }
return “register_failure.htm"; } catch (Exception) { return "errorpage.htm"; } }
Pattern 1: Timeouts
Identity Verification
Pattern 1: Timeouts
Site Server
private void BeginRegister(RegistrationInfo registrationInfo, Function<string> callback) { try {
identityService.EndIdentity += identityService_EndIdentity(callback) identityService.BeginIdentity(registrationInfo);
} catch (Exception) { callback("errorpage"); }
}
private void identityService_EndIdentity(bool success, Function<string> callback) { if (success) { callback("register_success.htm"); } callback("register_failure.htm"); }
Pattern 2: Non-blocking I/O
Pattern 2: Non-blocking I/O
Identity VerificationSite Server
For Users…
==
The site is stable. We’re still failing.
What’s the president recommending?
What might be happeningThank you. We’ll email
you when you are verified.
What might be happening
Identity Verification
“The” Registration ProcessWhen two principles are pushing in opposite directions, some underlying assumption is wrong. Often the word the is the culpritUdi Dahan
Read this againYou are the lead developer on a national health care site that will register millions of users a week. You are responsible for the signup process.
Your team must verify the identity of users with a third party API. You call the service and the third party system will return a boolean true if the identity is valid or false otherwise.
Pattern 3: Decoupling
Site Server
Thank you. We’ll email you when you are
verified
Pending Registration
Database
Pattern 3: Decoupling
Pending Registration
Database
Verification Application
Identity Verification
Scenario 2: ReliabilityYou are the lead developer on a hospital’s prescription filling service. Your RX wholesaler has provided you with an HTTPS endpoint to integrate with.
It is critical a prescription is not accidently prescribed twice and that prescriptions are not lost.
5. Success RX Service
2. Fill RX
3. RX IDSite Server
Reliability
1. Prescribe
Database
4. RX ID and Fill Info5. Record Updated
Invoking the Service private string Prescribe(PrescriptionInfo prescriptionInfo) { try { RxService rxService = new RxService(); int rxID = rxService.Prescribe(prescriptionInfo);
database.Save(rxId, prescriptionInfo);
return "success.htm"; }
catch (Exception) { return "errorpage.htm"; }
}
404 Timeout RX Service
2. Prescribe
Site Server
What if the network goes down?
1. Prescribe
Invoking the Service private string Prescribe(PrescriptionInfo prescriptionInfo) { try { RxService rxService = new RxService(); int rxID = rxService.Prescribe(prescriptionInfo); database.Save(rxId, prescriptionInfo);
return "success.htm"; }
catch (Exception) { return "errorpage.htm"; }
}
RX ServiceSite Server
Can I retry?
Prescribe
RX ServiceSite ServerPrescribe
Got it, but I couldn’t get Back to you.
404 Timeout
RX ServiceSite Server
Pattern 1: Idempotency
Prescribe
RX ServiceSite ServerPrescribe
Got it, but I couldn’t get Back to you.
404 Timeout
Sheesh… I already got it!
5. Success RX Service
2. Fill RX
3. RX IDSite Server
What if the database is down?
1. Prescribe
Database
4. Update Patient Record
Invoking the Service private string Prescribe(PrescriptionInfo prescriptionInfo) { try { RxService rxService = new RxService(); int rxID = rxService.Prescribe(prescriptionInfo);
database.Save(rxId, prescriptionInfo);
return "success.htm"; }
catch (Exception) { return "errorpage.htm"; }
}
Can We Guarantee this code? private string Prescribe(PrescriptionInfo prescriptionInfo) { try { RxService rxService = new RxService(); int rxID = rxService.Prescribe(prescriptionInfo);
database.Save(rxId, prescriptionInfo);
return "success.htm"; }
catch (Exception) { return "errorpage.htm"; }
}
Pattern 2: Transactional Queues
3. PendingSite Server
Transactional Queue
1. Prescribe
Fill RX Message Queue
Inserting into a Queue private string Prescribe(PrescriptionInfo prescriptionInfo) { try { Queue.save(new RXPrescribeMessage(prescriptionInfo)); return "rxPending.htm"; }
catch (Exception) { return "errorpage.htm"; } }
Transactional Queue
Queue
rxPrescribeMessage
RX Service
Fill rx
rx IDHandlerrxDBUpdateMessage
Transactional Queue
QueuerxDBUpdateMessage Save rxHandler Database
Message Handlers public void HandleRXPrescribeMessage(RXPrescribeMessage message) { var prescriptionInfo = message.prescriptionInfo;
RxService rxService = new RxService(); int rxID = rxService.Prescribe(prescriptionInfo); Queue.save(new RXDBUpdateMessage(rxID, prescriptionInfo)); }
public void HandleDBUpdateMessage(RXDBUpdateMessage message) { var rxId = message.rxID; var prescriptionInfo = message.prescriptionInfo
database.Update(message.rxID, message.prescriptionInfo) }
Nygard, Michael T. Cynical software expects bad things to happen and is never surprised when they do. Cynical software doesn’t even trust itself.. It refuses to get too intimate with other systems, because it could get hurt.