introduction to distributed architecture

61
Distributed Architecture Introduction to

Upload: justin-weinberg

Post on 21-Feb-2017

71 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Introduction to Distributed Architecture

Distributed Architecture

Introduction to

Page 2: Introduction to Distributed Architecture

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

Page 3: Introduction to Distributed Architecture

Why Architecture Matters

Page 4: Introduction to Distributed Architecture

Accidental Architecture

Every… system has an architecture. While some of these architectures are intentional, most appear to be accidental

Grady Booch

Page 5: Introduction to Distributed Architecture

Requirements Analysis

Design

Code and Test

Integration

System Test

Waterfall Process

Page 6: Introduction to Distributed Architecture

Requirements Analysis

Design

Code and Test

Integration

System Test

Waterfall Process

Analysis Paralysis

MassiveIntegration

Design divorced from reality

Page 7: Introduction to Distributed Architecture

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.

Page 8: Introduction to Distributed Architecture

Scrum: An agile Process

Page 9: Introduction to Distributed Architecture

Architect Code

Techies crave Extremes

Page 10: Introduction to Distributed Architecture

Functional requirementsWhat the system should do.• Use cases, User stories, acceptance criteria• Defines passing QA• Day to day you focus on this

Page 11: Introduction to Distributed Architecture

Nonfunctional requirementsWhat the system should be.• Extremely expensive or impossible to “fix”

later on• Defined passing Production• Assumed by your customers and users

Page 12: Introduction to Distributed Architecture

Nonfunctional Requirements• Availability• Stability• Efficiency• Reliability• Maintainability• Extensibility

• Fault Tolerance• Security• Capacity• Latency• Flexibility• Scalability

Page 13: Introduction to Distributed Architecture

Functional: Passed QABeautiful site (in my opinion)Easy to use

Nonfunctional: Failed ProductionAvailability StabilityLatency CapacityThroughput

Page 14: Introduction to Distributed Architecture
Page 15: Introduction to Distributed Architecture

ArchitectureThere is no best architecture

Page 16: Introduction to Distributed Architecture

Pacemakers and Guided Missiles

Page 17: Introduction to Distributed Architecture

The Flying Buttress

Page 18: Introduction to Distributed Architecture

Patterns

Page 19: Introduction to Distributed Architecture

Example: Layered Architecture

Page 20: Introduction to Distributed Architecture

Three Tier ArchitectureThe classic 3 tier architecture

Page 21: Introduction to Distributed Architecture

N-Tier ArchitectureBecause three tiers wasn’t enough!

Page 22: Introduction to Distributed Architecture

N-Tier Architecture

SHAREPOINT

BIZTALK

SQL SERVER

Windows Server 2008

SMS

License managementIIS

Page 23: Introduction to Distributed Architecture

Questions about Architecture?

Page 24: Introduction to Distributed Architecture

Distributed ArchitectureDesigns appropriate for small brochureware websites fail outrageously when applied to thousand-user, transactional, distributed systems...

Michael T. Nygard

Page 25: Introduction to Distributed Architecture

Key Constraints on Distributed Systems

• Stability • Reliability and fault tolerance• Consistency• Capacity and Scalability• Security

Page 26: Introduction to Distributed Architecture

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.

Page 27: Introduction to Distributed Architecture

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"; }

}

Page 28: Introduction to Distributed Architecture

6. RegisteredIdentity

Verification

Database

2. Verify

3. VerifiedSite Server

Stability

4. Save User5. User Saved

1. Register

Page 29: Introduction to Distributed Architecture

6. RegisteredIdentity

Verification

Database

2. Verify

3. VerifiedSite Server

Unbalanced Capacities

4. Save User5. User Saved

1. Register

Page 30: Introduction to Distributed Architecture

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

Page 31: Introduction to Distributed Architecture

Cascading Failures

Site Server

Site Server

Site Server

Site Server

Page 32: Introduction to Distributed Architecture

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

Page 33: Introduction to Distributed Architecture

Identity Verification

Pattern 1: Timeouts

Site Server

Page 34: Introduction to Distributed Architecture

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

Page 35: Introduction to Distributed Architecture

Pattern 2: Non-blocking I/O

Identity VerificationSite Server

Page 36: Introduction to Distributed Architecture

For Users…

==

Page 37: Introduction to Distributed Architecture

The site is stable. We’re still failing.

Page 38: Introduction to Distributed Architecture

What’s the president recommending?

Page 39: Introduction to Distributed Architecture

What might be happeningThank you. We’ll email

you when you are verified.

Page 40: Introduction to Distributed Architecture

What might be happening

Identity Verification

Page 41: Introduction to Distributed Architecture

“The” Registration ProcessWhen two principles are pushing in opposite directions, some underlying assumption is wrong. Often the word the is the culpritUdi Dahan

Page 42: Introduction to Distributed Architecture

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.

Page 43: Introduction to Distributed Architecture

Pattern 3: Decoupling

Site Server

Thank you. We’ll email you when you are

verified

Pending Registration

Database

Page 44: Introduction to Distributed Architecture

Pattern 3: Decoupling

Pending Registration

Database

Verification Application

Identity Verification

Page 45: Introduction to Distributed Architecture

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.

Page 46: Introduction to Distributed Architecture

5. Success RX Service

2. Fill RX

3. RX IDSite Server

Reliability

1. Prescribe

Database

4. RX ID and Fill Info5. Record Updated

Page 47: Introduction to Distributed Architecture

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"; }

}

Page 48: Introduction to Distributed Architecture

404 Timeout RX Service

2. Prescribe

Site Server

What if the network goes down?

1. Prescribe

Page 49: Introduction to Distributed Architecture

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"; }

}

Page 50: Introduction to Distributed Architecture

RX ServiceSite Server

Can I retry?

Prescribe

RX ServiceSite ServerPrescribe

Got it, but I couldn’t get Back to you.

404 Timeout

Page 51: Introduction to Distributed Architecture

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!

Page 52: Introduction to Distributed Architecture

5. Success RX Service

2. Fill RX

3. RX IDSite Server

What if the database is down?

1. Prescribe

Database

4. Update Patient Record

Page 53: Introduction to Distributed Architecture

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"; }

}

Page 54: Introduction to Distributed Architecture

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"; }

}

Page 55: Introduction to Distributed Architecture

Pattern 2: Transactional Queues

Page 56: Introduction to Distributed Architecture

3. PendingSite Server

Transactional Queue

1. Prescribe

Fill RX Message Queue

Page 57: Introduction to Distributed Architecture

Inserting into a Queue private string Prescribe(PrescriptionInfo prescriptionInfo) { try { Queue.save(new RXPrescribeMessage(prescriptionInfo)); return "rxPending.htm"; }

catch (Exception) { return "errorpage.htm"; } }

Page 58: Introduction to Distributed Architecture

Transactional Queue

Queue

rxPrescribeMessage

RX Service

Fill rx

rx IDHandlerrxDBUpdateMessage

Page 59: Introduction to Distributed Architecture

Transactional Queue

QueuerxDBUpdateMessage Save rxHandler Database

Page 60: Introduction to Distributed Architecture

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) }

Page 61: Introduction to Distributed Architecture

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.