Ref: https://learn.cantrill.io/courses/1820301/lectures/41301398
Serverless - Basic Concepts
- đź”§Â Main idea: manage few (if any) servers
- 💡 Serverless isn't one single thing… it's a concept more than anything
- More a SW architecture than a HW architecture!
- Servers carry overhead: cost, administration & risk
- 👍 Without server management, overhead is greatly reduced
- Serverless architecture takes the best things from microservices & EDA
- ‼️ Despite the name “serverless” there ARE actually servers running behind the scenes!! xD
- …You just don't manage them!
- AWS has tons of managed services and products that support serverless architectures
- 💡 Don't expect to know them all. More important is to understand how serverless works.
Characteristics of Serverless Applications
- Apps are a collection of small & specialized functions
- Even smaller than servers in microservices!
- Functions do small things very, very well. They start, execute & stop.
- Functions only bill for resources consumed during their execution
- Stateless and ephemeral environments
- Functions can run anywhere
- Event-driven
- Consumption only when being used → consumption-based model
- Little, if any, costs incurred for base usage (i.e. no events & nothing running)
- Managed services used where possible → don't reinvent the wheel
- e.g. S3 for persistent object storage, DynamoDB for persistent data storage, External ID providers instead of building your own…
- âť—Â Consume as a service as much as possible, code as little as possible
- FaaS used where possible for general purpose compute, if needed
- Cheap & easy to scale. Each environment is easy to provision & predictably the same
- In AWS: Lambda (in Azure: Azure Functions)
- Default is to NOT use self-managed compute (i.e. no servers, no EC2 instances)
Example of a Simple Serverless Architecture
Diagram: https://github.com/acantril/aws-sa-associate-saac03/blob/main/1600-SERVERLESS_and_APPLICATION_SERVICES/00_LEARNINGAIDS/Serverless-1.png
- 💡 We continue with CatTube example app from previous Architecture Deep Dive section
- 💡 Simplified architecture → in reality we would have e.g. APIGW between client and Lambda functions
- ‼️ Notice how there are absolutely NO managed servers in the whole architecture!!!
- No self-managed DB servers either!!
- Frontend: S3 static website with HTML pages that inject JavaScript to browser
- Modern browsers can run client-side JavaScript inside the browser
- Authentication: Third-party identity provider (e.g. Google IDP)
- IDP returns ID token after successful authentication
- AWS can't use third-party ID tokens → browser communicates with Amazon Cognito
- Cognito swaps IDP token for AWS temporary credentials (with an IAM role) → client can now access AWS resources