Being ElasticEvolving Programming for the CloudRandy ShoupeBay Chief EngineerQCon San FranciscoNovember 4, 2010
Cloud is a New EcosystemResource-RichInexpensiveAvailableElasticManagedRemoteVirtualVariableEphemeralMetered
The Old and the Newflickr.com/photos/slapbcn/2035854990/
Developers Must AdaptBenefits are hugeConstraints are realAdapt to the constraints to get the benefitsMost adaptations force otherwise good development practices (!)
Scaling for the CloudTo leverage scalable infrastructure, you needScalable applicationScalable development practicesScalable culturePrinciples and practices discussed widely (particularly at QCon!)Convergence of Architecture, Agile, DevOps, etc.
Universal Scalability LawThroughput limited by two factorsContention (α):  queueing on shared resourceCoherency (β):  communication and coordination among multiple nodesFormulated by Neil GuntherGeneralization of Amdahl’s LawGrounded in real-world physical processeshttp://www.perfdynamics.com/Manifesto/USLscalability.html
Programming in the CloudParallelismLayeringServicesState managementData modelFailure handlingTesting
ParallelismThink parallel!Simple parallel algorithm out-scales “smarter” non-parallel algorithmExploiting elasticity fundamentally requires parallelismRequest processingParallelism through Routing requestsAggregating servicesQueueing workAsync I/O and Futures are your friendsflickr.com/photos/sharif/2423144088/
ParallelismOffline computationParallelism through Workload partitioningPartitioning data and processingE.g., pipelines, MapReduceflickr.com/photos/sharif/2423144088/“There are 3 rules to follow when parallelizing large codes.  Unfortunately, no one knows what these rules are.” – W. Somerset Maugham and Gary Montry
LayeringStrictly layered systemEach software layer handles a single set of responsibilitiesCloud makes this particularly importantCommon code in frameworksConfigurationInstrumentationFailure management“All problems in computer science can be solved by another level of indirection … Except for the problem of too many layers of indirection.” – David Wheeler
ServicesDecompose system functionality into servicesSimpleSingle-purposeModularStatelessMulti-instanceCompose complex application behavior from simple elements“Make everything as simple as possible, but not simpler.” – Albert Einstein
ServicesThe service should be the fundamental unit of …CompositionCombine simple services into complex systemsDependencyDepend on a service interface, not implementationAddressingTalk to logical endpoint (URI), not IP:portPersistenceAbstract and isolate persistence within a serviceDeployment
State ManagementStateless instancesInstances are ephemeralMemory / storage is fast and local, but transient and inconsistent Equivalent to a cacheDurable state in persistent storage(Many implementations)“Here today, gone tomorrow.” – American proverb
Key-Value Data ModelDistributed key-value storesSimpleHorizontally scalable(Many implementations)Constrained by designCannot express complex relationshipsLimited schemaPredictable, bounded performanceGreater burden on applicationJoins, aggregations, sorts, etc.Integrity and schema validation
Key-Value Data ModelPlan to ShardPartition by keyParallelize writes for write throughputParallelize reads for read throughputPlan to DenormalizeOptimize for readsPrecalculate joins, aggregations, sortsUse async queue to updateLearn to tolerate transient inconsistency
Failure HandlingExpect failures and handle theme.printStackTrace() does not count!Failure handling meansGraceful degradationTimeouts and retriesThrottling and back-offAbstract through frameworks and policiesflickr.com/photos/davidwatts1978/3199405401/“Hope is not a strategy.” – Various
TestingTest early and oftenTest-driven and Test-first approaches work particularly well in the cloudAutomated testing works particularly wellIncremental development and deploymentTest end-to-endMuch easier to test at loadMore challenging to simulate all combinations and failure modes“In the data center, robust code is best practice.  In the cloud, it is essential.” – Adrian Cockcroft
Operating in the CloudDevOps MindsetConfiguration InjectionInstrumentationMonitoringMetering
DevOps MindsetIn the Cloud, Developers  OpsEveryone will use tools for deployment, monitoring, etc.Manageability as an investmentManagement interfaces need as much engineering discipline as functional interfacesAutomate, automate, automateRepeatable builds and deploymentsProvisioning, scaling, failure management, etc.If you do it more than twice, script it
Configuration InjectionBoot instance from bare minimum packageExternalize all variabilitySeparate code and configurationConfiguration should driveInstance roleService and resource dependenciesBehavior / capabilities InjectAt boot timeAt runtimeflickr.com/photos/andresrueda/2983149263/“I do my work at the same time each day – the last minute.” – Unknown
InstrumentationFully instrument all componentsCannot attach debugger / profilerRemotely diagnose, profile, debugAvoid “monitoring fatigue”Logging is insufficientNeeds to be automatically interpretable and actionableUse a frameworkMake part of your infrastructureflickr.com/photos/wwarby/3016549999/
MonitoringMonitor requests end-to-endTrace all requests as they flow from component to componentMonitor component activity and performanceMetrics, metrics, metricsUnderstand your typical system behaviorSpiky, flat, sinusoidal?Know the baseline so you know what is abnormalflickr.com/photos/pdstahl/3884421899/
MeteringFixed cost -> variable costProcessingStorageNetworkEfficiency mattersAny savings goes directly to the bottom lineAny inefficiency is multiplied by many instances (!)“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.” – Donald Knuth
Evolving for the Cloud“It is not the strongest of the species that survives, nor the most intelligent that survives. It is the one that is the most adaptable to change.” – Charles Darwin

Being Elastic -- Evolving Programming for the Cloud

  • 1.
    Being ElasticEvolving Programmingfor the CloudRandy ShoupeBay Chief EngineerQCon San FranciscoNovember 4, 2010
  • 2.
    Cloud is aNew EcosystemResource-RichInexpensiveAvailableElasticManagedRemoteVirtualVariableEphemeralMetered
  • 3.
    The Old andthe Newflickr.com/photos/slapbcn/2035854990/
  • 4.
    Developers Must AdaptBenefitsare hugeConstraints are realAdapt to the constraints to get the benefitsMost adaptations force otherwise good development practices (!)
  • 5.
    Scaling for theCloudTo leverage scalable infrastructure, you needScalable applicationScalable development practicesScalable culturePrinciples and practices discussed widely (particularly at QCon!)Convergence of Architecture, Agile, DevOps, etc.
  • 6.
    Universal Scalability LawThroughputlimited by two factorsContention (α): queueing on shared resourceCoherency (β): communication and coordination among multiple nodesFormulated by Neil GuntherGeneralization of Amdahl’s LawGrounded in real-world physical processeshttp://www.perfdynamics.com/Manifesto/USLscalability.html
  • 7.
    Programming in theCloudParallelismLayeringServicesState managementData modelFailure handlingTesting
  • 8.
    ParallelismThink parallel!Simple parallelalgorithm out-scales “smarter” non-parallel algorithmExploiting elasticity fundamentally requires parallelismRequest processingParallelism through Routing requestsAggregating servicesQueueing workAsync I/O and Futures are your friendsflickr.com/photos/sharif/2423144088/
  • 9.
    ParallelismOffline computationParallelism throughWorkload partitioningPartitioning data and processingE.g., pipelines, MapReduceflickr.com/photos/sharif/2423144088/“There are 3 rules to follow when parallelizing large codes. Unfortunately, no one knows what these rules are.” – W. Somerset Maugham and Gary Montry
  • 10.
    LayeringStrictly layered systemEachsoftware layer handles a single set of responsibilitiesCloud makes this particularly importantCommon code in frameworksConfigurationInstrumentationFailure management“All problems in computer science can be solved by another level of indirection … Except for the problem of too many layers of indirection.” – David Wheeler
  • 11.
    ServicesDecompose system functionalityinto servicesSimpleSingle-purposeModularStatelessMulti-instanceCompose complex application behavior from simple elements“Make everything as simple as possible, but not simpler.” – Albert Einstein
  • 12.
    ServicesThe service shouldbe the fundamental unit of …CompositionCombine simple services into complex systemsDependencyDepend on a service interface, not implementationAddressingTalk to logical endpoint (URI), not IP:portPersistenceAbstract and isolate persistence within a serviceDeployment
  • 13.
    State ManagementStateless instancesInstancesare ephemeralMemory / storage is fast and local, but transient and inconsistent Equivalent to a cacheDurable state in persistent storage(Many implementations)“Here today, gone tomorrow.” – American proverb
  • 14.
    Key-Value Data ModelDistributedkey-value storesSimpleHorizontally scalable(Many implementations)Constrained by designCannot express complex relationshipsLimited schemaPredictable, bounded performanceGreater burden on applicationJoins, aggregations, sorts, etc.Integrity and schema validation
  • 15.
    Key-Value Data ModelPlanto ShardPartition by keyParallelize writes for write throughputParallelize reads for read throughputPlan to DenormalizeOptimize for readsPrecalculate joins, aggregations, sortsUse async queue to updateLearn to tolerate transient inconsistency
  • 16.
    Failure HandlingExpect failuresand handle theme.printStackTrace() does not count!Failure handling meansGraceful degradationTimeouts and retriesThrottling and back-offAbstract through frameworks and policiesflickr.com/photos/davidwatts1978/3199405401/“Hope is not a strategy.” – Various
  • 17.
    TestingTest early andoftenTest-driven and Test-first approaches work particularly well in the cloudAutomated testing works particularly wellIncremental development and deploymentTest end-to-endMuch easier to test at loadMore challenging to simulate all combinations and failure modes“In the data center, robust code is best practice. In the cloud, it is essential.” – Adrian Cockcroft
  • 18.
    Operating in theCloudDevOps MindsetConfiguration InjectionInstrumentationMonitoringMetering
  • 19.
    DevOps MindsetIn theCloud, Developers  OpsEveryone will use tools for deployment, monitoring, etc.Manageability as an investmentManagement interfaces need as much engineering discipline as functional interfacesAutomate, automate, automateRepeatable builds and deploymentsProvisioning, scaling, failure management, etc.If you do it more than twice, script it
  • 20.
    Configuration InjectionBoot instancefrom bare minimum packageExternalize all variabilitySeparate code and configurationConfiguration should driveInstance roleService and resource dependenciesBehavior / capabilities InjectAt boot timeAt runtimeflickr.com/photos/andresrueda/2983149263/“I do my work at the same time each day – the last minute.” – Unknown
  • 21.
    InstrumentationFully instrument allcomponentsCannot attach debugger / profilerRemotely diagnose, profile, debugAvoid “monitoring fatigue”Logging is insufficientNeeds to be automatically interpretable and actionableUse a frameworkMake part of your infrastructureflickr.com/photos/wwarby/3016549999/
  • 22.
    MonitoringMonitor requests end-to-endTraceall requests as they flow from component to componentMonitor component activity and performanceMetrics, metrics, metricsUnderstand your typical system behaviorSpiky, flat, sinusoidal?Know the baseline so you know what is abnormalflickr.com/photos/pdstahl/3884421899/
  • 23.
    MeteringFixed cost ->variable costProcessingStorageNetworkEfficiency mattersAny savings goes directly to the bottom lineAny inefficiency is multiplied by many instances (!)“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.” – Donald Knuth
  • 24.
    Evolving for theCloud“It is not the strongest of the species that survives, nor the most intelligent that survives. It is the one that is the most adaptable to change.” – Charles Darwin