{"id":2672,"date":"2019-04-27T21:11:30","date_gmt":"2019-04-27T19:11:30","guid":{"rendered":"http:\/\/miro.borodziuk.eu\/?p=2672"},"modified":"2020-02-16T23:26:56","modified_gmt":"2020-02-16T22:26:56","slug":"serverless-compute","status":"publish","type":"post","link":"http:\/\/miro.borodziuk.eu\/index.php\/2019\/04\/27\/serverless-compute\/","title":{"rendered":"Serverless Compute"},"content":{"rendered":"<p>A <span style=\"color: #3366ff;\">microservices architecture<\/span> is the inverse of a monolithic architecture. Instead of having all system functions in one codebase, components are separated into microservices and operate independently. A microservice does one thing \u2014 and does it well. Operations, updates, and scaling can be done on a per-microservice basis.<\/p>\n<p><!--more--><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2675\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/Microservices1.jpg\" alt=\"\" width=\"616\" height=\"169\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/Microservices1.jpg 616w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/Microservices1-300x82.jpg 300w\" sizes=\"(max-width: 616px) 100vw, 616px\" \/><br \/>\nInflexible scaling: Either increasing the instance size or duplicating the instance<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2676\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/InflexibleScaling.jpg\" alt=\"\" width=\"560\" height=\"221\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/InflexibleScaling.jpg 560w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/InflexibleScaling-300x118.jpg 300w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><br \/>\nMicroservices operate as independent applications. They allow direct communication between components and the end user. If one part of the system requires more capacity, that service can be scaled and updated as needed.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">API<\/span><\/p>\n<p>You access the AWS Console via a user interface, which is designed for a human being. An API (or application programming interface) is an interface accessed (consumed) by another service or application.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2677\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/API.jpg\" alt=\"\" width=\"530\" height=\"409\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/API.jpg 530w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/API-300x232.jpg 300w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><br \/>\nAn API endpoint hosts one or more APIs and makes them available on a network (private or public internet). APIs remain static \u2014 they are abstracted from what the code inside the service is doing. API consumers don&#8217;t care how things are done \u2014 only that the interface works. That&#8217;s what allows lower-risk changes.<\/p>\n<p>The AWS CLI tools use the AWS APIs.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>When using an <span style=\"color: #3366ff;\">event-driven<\/span> architecture, a system operates around &#8220;events&#8221; that represent an action or a change of state &#8211; e.g., a button being clicked, a file being uploaded, or a temperature dropping below a certain level.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2679\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/EventDriven.jpg\" alt=\"\" width=\"592\" height=\"487\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/EventDriven.jpg 592w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/EventDriven-300x247.jpg 300w\" sizes=\"(max-width: 592px) 100vw, 592px\" \/><\/p>\n<p>It&#8217;s efficient because events are generated and pushed, rather than things being polled. Polling requires always-on compute and doesn&#8217;t scale well.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2678\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/TraditionalArch.jpg\" alt=\"\" width=\"594\" height=\"486\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/TraditionalArch.jpg 594w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/TraditionalArch-300x245.jpg 300w\" sizes=\"(max-width: 594px) 100vw, 594px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">Serverless<\/span> architecture consists of two main principles, including BaaS (or Backend as a Service), which means using third-party services where possible rather than running your own. Examples include AuthO or Cognito for authentication and Firebase or DynamoDB for data storage.<br \/>\nServerless also means using an event-driven architecture where possible, using FaaS (or Function as a Service) products to provide application logic. These functions are only active (invoked) when they are needed (when an event is received).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2680\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/ServerlessCompute.jpg\" alt=\"\" width=\"607\" height=\"491\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/ServerlessCompute.jpg 607w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/ServerlessCompute-300x243.jpg 300w\" sizes=\"(max-width: 607px) 100vw, 607px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">Lambda<\/span> is a FaaS product. Functions are code, which run in a runtime. Functions are invoked by events, perform actions for up to 15 minutes, and terminate. Functions are also stateless \u2014 each run is clean.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2681\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/Lambda.jpg\" alt=\"\" width=\"605\" height=\"630\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/Lambda.jpg 605w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/Lambda-288x300.jpg 288w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">API Gateway<\/span> is a managed API endpoint service. It can be used to create, publish, monitor, and secure APIs &#8220;as a service.&#8221; API Gateway can use other AWS services for compute (FaaS\/IaaS) as well as to store and recall data.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2682\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/APIGateway.jpg\" alt=\"\" width=\"613\" height=\"640\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/APIGateway.jpg 613w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/APIGateway-287x300.jpg 287w\" sizes=\"(max-width: 613px) 100vw, 613px\" \/><\/p>\n<p>Pricing is based on the number of API Calls, the data transfered and any caching required to improve performance.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2683\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/APIGatewayPricing.jpg\" alt=\"\" width=\"607\" height=\"558\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/APIGatewayPricing.jpg 607w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/APIGatewayPricing-300x276.jpg 300w\" sizes=\"(max-width: 607px) 100vw, 607px\" \/><\/p>\n<p>APIs can be migrated to API Gateway in a monolithic form, and gradually moved to a microservices architecture and then once components have been fully broken up a serverless &amp; FaaS based architecture.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff;\">Step Functions<\/span> is a serverless visual workflow service that provides state machines. A state machine can orchestrate other AWS services with simple logic, branching, and parallel execution, and it maintains a state. Workflow steps are known as states, and they can perform work via tasks. Step Functions allows for long-running serverless workflows. A state machine can be defined using Amazon States Language (ASL).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2684\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/StepFunction.jpg\" alt=\"\" width=\"620\" height=\"551\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/StepFunction.jpg 620w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/StepFunction-300x267.jpg 300w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>Without Step Functions, Lambda functions could only run for 15 minutes. Lambda functions are stateless. State machines maintain state and allow longer-running processes. Step Functions &#8220;replaces&#8221; SWF with a serverless version.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A microservices architecture is the inverse of a monolithic architecture. Instead of having all system functions in one codebase, components are separated into microservices and operate independently. A microservice does one thing \u2014 and does it well. Operations, updates, and scaling can be done on a per-microservice basis.<\/p>\n","protected":false},"author":1,"featured_media":2690,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76],"tags":[],"_links":{"self":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/2672"}],"collection":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/comments?post=2672"}],"version-history":[{"count":4,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/2672\/revisions"}],"predecessor-version":[{"id":3334,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/2672\/revisions\/3334"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media\/2690"}],"wp:attachment":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media?parent=2672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/categories?post=2672"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/tags?post=2672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}