楚阿旗

博客园 首页 新随笔 联系 订阅 管理

Intriduction to Severless Computing

Define serverless computing and describe its concepts

  • Serverless computing is the concept of building and running applications that do not require server management
  • It describes a finer-grained deployment model where applications, bundled as one or more functions, are uploaded to a platform and then executed, scaled , and billed in response to the exact demand needed at the moment.

Serverless = FaaS + BaaS

FaaS paltform are used to run functions

BaaS represents backend cloud services, such as databases obkect storage, and message queues

Identify key characteristics of serverless computing

Serverless architecture concepts

  • Abstracts infrastructure and software environment
  • Code runs in a cloud platform
  • Cloud provider manages the hardware and software setup, security, performance
  • Billed only for usage
  • Developers only need to focus on applications and code in the form of functions

Serverless characteristics

  • Hostless
  • Elastic
  • Load balanced
  • Stateless
  • Event driven
  • Highly available
  • Usage-based/granular billing

Developer's role

Focus on application developemnt

Build functions using a popular programming language

  • Extend functionality
  • Perform better testing 
  • Optimize apps and functions
  • Improve user experience

Cloud provide responsibilities

Cloud providers manage common infrastructure and maintenance task such as:

  • Maximizing utilization
  • Minimizing costs
  • Server management
  • Autoscaling
  • High availability
  • Security
  • Performance(low latency)
  • Monitoring and logging

Serverless Pros and cons

  • In traditional computing, developement and operations team sr u adn maintain infrastructure
  • Setup and deployment are time-consumin, complex, and expersive
  • Arrival of cloud, containers, and serverless computing means developers can focus on writeing high-quality code
  • Developers can build and run applications in milliseconds without worrying about infrastructiure, scalability, and fault tolerance
  • Challenges include vendor lock-in, 3rd-party dependencies, and networking

Serverless computing benefits

  • Reduced costs
  • Built-in HA and FT
  • Increased dev productivity
  • Code runs when triggered
  • Fast run time
  • Built-in code editor
  • Pay as you go
  • Language independent
  • Third-party auth and DB services
  • Faster time to market
  • Innovate and experiment
  • Green computing

Serverless computing constraints

  • Unsuitable for long-running processes
  • Vendor lock-in risks
  • Cold starts
  • Latency unsuitable for tim-critical apps
  • Security concerns
  • Complex monitoring and debugging
  • Language support dependency
  • Server optimization loss 
  • No state persistence

Introduction to the FaaS model

Whait is FaaS

  • Function as a Service
  • Cloud-computing withoit complex infrastructure

FaaS characteristics

  • Subset of serverless computing
  • Creates applications as functions
  • Deploys on hybrid and on-premise
  • Stateless
  • Includes functions that execute in milliseconds and are insstantaneously scalable
  • Lightweight and decoupled
  • Billed on consumption and execution not on server size

FaaS benefits

  • Divides server into functions
    • Focus more on code
    • Reduce time-to-market
  • Pay for what you use
  • Functions are stateless, small, independent pieces of code
    • Scale auto automatically and independently as required
    • Scale down automatically, if demand frops
  • Inherent high availability
    • Spread across regions and availability zones

How serverless stack components work 

Functions in action

  • User selects profile photo
  • Profile photo image is uploaded to IBM Cloud Object Storage
  • Function is triggered
  • An IBM Cloud Function creates the profile photo thumbnail image
  • Profile photo thumbnail image is uplaoded to IBM Cloud Object Storage

FaaS principles and best practices

  • Make each function perform only one action 
    • Make your code scope limited, efficient and lightweight
    • Functions load and execute quickly
  • Avoid function chaining
    • Too many functions increases cost
  • Limit dependencies on third-party libraries
    • Slows down initialization
    • Makes them harder to scale

Managed FaaS provider

  • Amazon - AWS Lambda
  • Google Cloud Functions 
  • Microsoft - Azure Functions
  • IBM CLoud Functions
  • Red Hat - OpenShift CLoud Functions

The Serverless Framework

What is the Serverless Framework? The Serverless Framework is a free and open-source web framework written using Node.js. Originally designed for provisioning AWS Lambda Functions, Events, and infrastructure Resources rapidly and securely, it has expanded to support other cloud providers like Microsoft Azure, Google Cloud Platform, and Apache OpenWhisk.

Serverless Framework Concepts

  • Functions: These are independent units of execution and deployment, akin to microservices, performing specific tasks like saving a user to a database or executing a job at a specified time.
  • Events: Functions are triggered by events originating from various resources, such as HTTP requests on API Gateway URLs or new file uploads in S3 buckets.
  • Resources: Infrastructure components utilized by functions, like databases provided as services by cloud providers or S3 buckets for file storage.
  • Services: The organizational unit of the Framework, akin to project files, though multiple services can exist for a single application. Configured via a serverless.yml file where functions, events, and resources are defined for deployment.
  • serverless.yml: Controls all aspects of the service configuration, with specific sections for defining functions, events, and resources.

Serverless Framework - Hello World

To set up and deploy a basic "Hello World" application using the Serverless Framework on AWS:

  1. Install the Serverless CLI globally using npm: npm install -g serverless.
  2. Use the serverless command to create the initial AWS HTTP API using Python. This command guides you through a wizard.
  3. After deployment, you'll receive a URL. Opening this URL in a browser should display the expected outcome.
  4. Modify the function code to return "Hello World" upon request.
  5. Redeploy the function using the Serverless CLI and test again.

Serverless Reference Architecture and Use Casese

Web Application - To Do

Web Application - Components

  1. Front End:

    • Static content generated using Create React App.
    • Consists of HTML files, CSS for styling, JavaScript for client-side functionality, and images.
    • Hosted on AWS Amplify Console.
    • Resources downloaded to the user's browser upon connecting to the website.
  2. Back End:

    • Hosts the business logic implemented in Lambda functions.
    • Accessed by the front end via API Gateway using REST API.
    • Data stored in DynamoDB.
    • Ensures users are limited to their own to-do items and requires registration and authentication.
  3. User Registration and Authentication:

    • Utilizes Cognito User Pools for user registration and authentication.
    • Allows users to register to the application and authenticates them, ensuring access only to their individual to-do items.

Web Application - Architecture

  • Event-driven architecture utilizing:
    • AWS Lambda: AWS Lambda is a serverless compute service that allows you to run code in response to events without managing servers.
    • Amazon API Gateway: It acts as a frontend for your backend services, providing a secure and scalable API endpoint for client applications to interact with. API Gateway can handle tasks such as authentication and authorization, request and response transformations, and rate limiting.
    • Amazon DynamoDB: a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability.
    • Amazon Cognito: a service that provides authentication, authorization, and user management for web and mobile applications.
    • AWS Amplify Console: a continuous deployment and hosting service for web applications. It simplifies the deployment process by automatically building and deploying your frontend applications to a global content delivery network (CDN). Amplify Console provides features like custom domains, SSL/TLS certificates, and branch previews, enabling you to deliver your application to end users with low latency and high availability.

 

Use cases:

  1. Event Streaming:

    • Enables building applications without upfront infrastructure.
    • Triggered from publisher-subscriber topics or event logs.
    • Provides elastic, scalable event pipelines for analytics, updating secondary data stores, caching, or monitoring systems.
  2. Post-processing:

    • Involves tasks like image and video manipulation.
    • Dynamically resize images, change video transcoding for different devices.
    • Utilized for image recognition or AI purposes, such as detecting shadows on passport photos.
  3. Multi-language:

    • Serverless applications allow flexibility in language choice.
    • Prevents language lock-in, enabling teams to use the most suitable language for their project without being bound to legacy software choices.

Popular Serverless Platforms

AWS Lambda:

  • Description: AWS Lambda is a serverless, event-driven computing service provided by Amazon Web Services.
  • Key Features:
    • Runs code without managing servers.
    • Scales automatically based on incoming requests.
    • Supports over 200 AWS services.
    • Charged only for function execution and data transfer.
  • Use Cases: File processing, web applications, IoT, mobile back-ends.

Google Cloud Functions:

  • Description: Google Cloud Functions offers a simple and intuitive developer experience for serverless computing.
  • Key Features:
    • Automatically scales to zero depending on traffic.
    • Seamless integration with Google Firebase for real-time data sync.
    • Supports lightweight ETL functions without individual servers.
  • Use Cases: Real-time data processing, lightweight ETL tasks.

Microsoft Azure Functions:

  • Description: Microsoft Azure Functions is a serverless solution that enables writing less code and maintaining less infrastructure.
  • Key Features:
    • Supports multiple programming languages.
    • Excellent DevOps capabilities for continuous integration and delivery.
    • Offers Consumption, Premium, and App Service plans for different needs.
  • Use Cases: File processing, IoT data collection, scheduled tasks.

IBM Cloud Functions:

  • Description: IBM Cloud Functions provides high availability and cost-effective computing for serverless applications.
  • Key Features:
    • Pay only for what you use, down to one-tenth of a second.
    • Seamless integration with IBM Watson for cognitive services.
    • High availability across multiple IBM Cloud regions.
  • Use Cases: Image and video processing, event-driven actions.

Knative:

    • Description: Knative is an open-source serverless platform based on containers running via Kubernetes.
    • Key Features:
      • Avoids vendor lock-in by leveraging Kubernetes.
      • Platform-agnostic, deployable on any Kubernetes-supported cloud.
      • Allows gradual traffic shifting for rollout strategies.
    • Use Cases: Container-based serverless applications, multi-cloud deployments.
 
posted on 2024-04-13 15:26  楚阿旗  阅读(3)  评论(0编辑  收藏  举报