Building Large Scale,
Microservice-driven Applications
Andrei Papancea ¡¯15
Columbia University, MS Computer Science
Copyright By PowCoder代写 加微信 powcoder
NLX Inc, CEO & Co-Founder
Dealing with Large Scale Applications
Channel(s)
Security Requirements
Platform(s)
Availability Cost
Learn how to build highly available, distributed, and scalable systems that are also cost-effective, using Microservices.
1. Problems with Monolithic Systems
2. Microservices:ASolution
3. Microservice-drivenAPIs
4. Scaling the Frontend
5. Asynchronous Workflows
You have a great idea for a new AI-powered concierge service.
You set up a quick MVP to get your product out there.
Your new website is up!
Now you scale from 100 users to 100k.
Solution? Scale out.
Load Balancer
But, adding more servers can get very expensive.
A security backdoor has been discovered in the server software that you use.
Solution? Patch all your instances.
Ugh, managing servers is time consuming.
You realize your NLP operations consume too much memory.
Your solution? Increase instance memory.
Everything starts getting more and more expensive.
Alex, one of the developers, decides to deploy the feature he has been working on all week.
…Sam committed non-working code to the master branch.
The new feature can¡¯t be deployed until Sam fixes the bugs. Frustrating.
Challenges with Monolithic Systems
¡ñ Code complexity and maintainability
¡ñ Deployment becomes the bottleneck
¡ñ Fear to change
¡ñ Lack of ownership
¡ñ Failure dependencies
¡ñ One size doesn¡¯t fit all
¡ñ Hard to scale out
1. Problems with Monolithic Systems
2. Microservices:ASolution
3. Microservice-drivenAPIs
4. Scaling the Frontend
5. Asynchronous Workflows
Microservices to the rescue!
¡ñ An architectural pattern
¡ñ Split the application into multiple services that:
¡ð Are small
¡ð Use simple protocols
¡ð Are loosely-coupled
¡ð Can be independently deployed
¡ð + each can be written in a different language
Benefits of Microservices
¡ñ Faster development & deployments
Innovation
¡ñ Autonomy of teams, culture of change
¡ñ Composability and reusability
¡ñ More maintainable ¡ñ Ownership and code
DevOps culture
¡ñ Better scaling and optimizations
¡ñ Failure Isolation and Resiliency
Microservices++: Serverless Components
¡ñ No servers to manage
¡ñ Scalability out of the box
¡ñ Minimize codebase size
¡ñ Pay per usage
¡ñ Extremely low cost (usually fractions of a cent)
Your new best friends.
Your new best friends.
Lambda API Gateway
Your new best friends.
Lambda API Gateway Cognito
Your new best friends.
Lambda API Gateway Cognito IAM
1. Microservices are an architectural pattern used to decouple applications
2. AWS offers lots of different managed services, that can be used as building blocks in your microservice-driven systems
1. Problems with Monolithic Systems
2. Microservices:ASolution
3. Microservice-drivenAPIs
4. Scaling the Frontend
5. Asynchronous Workflows
Let¡¯s build our Concierge Service.
Walkthrough of our Concierge app.
Where do I start?
Design. Design. Design.
Not (just) UI design
¡ñ Stack design
¡ñ Architecture design
¡ñ Data structure design
¡ñ API design
API Design
¡ñ forces you to think before you build
¡ñ drives a good chunk of the architecture
¡ñ drives the data structure design
¡ñ makes everything more efficient
¡ð no more ¡°I¡¯m waiting for the backend to be ready before I can start to implement the frontend¡±
¡ð minimizes time wasted restructuring the API in future versions
Yeah … but building documentation sucks and it is time consuming.
That¡¯s why there¡¯s Swagger.
¡ñ ¡°The world¡¯s most popular API framework¡±
¡ñ Powerful tool to design, build, document, and
consume REST APIs
¡ñ Open Source
¡ñ User friendly
¡ñ Standardized
Check out http://swagger.io
Swagger + API Gateway =
¡ñ Seamless API setup
¡ñ Import the Swagger configuration into API Gateway
¡ð endpoints
¡ð security settings
¡ð request/response models
¡ð request/response mapping
¡ð response codes, etc.
Swagger + API Gateway + Lambda =
¡ñ Custom Swagger definitions for Lambda
¡ñ Set up a fully integrated and managed API
¡ñ Built-in API management features
¡ð API keys
¡ð Throttling
¡ð Security
¡ð Staging, etc.
Setup the API using Swagger, API Gateway, Lambda
Code Deployment with Lambda
¡ñ Using the AWS Web Console
¡ñ Using the AWS CLI (preferred)
¡ñ Bash script
¡ñ Check out the sample deployment script
¡ð https://github.com/mangatanyc/columbia-lecture-concierge/
blob/master/backend/deploy.sh
Our Stack so far
API Gateway
What¡¯s missing?
Our API is accessible by anyone on the internet.
IAM: Identity and Access Management
¡ñ Fine-grained access control to AWS resources ¡ð including API Gateway
¡ñ Create roles and permissions
¡ñ Integrate with your corporate directory
¡ñ Uses Access and Secret key pairs for access control
¡ð Can be used to sign API calls to AWS
Awesome! When was the last time you signed your API requests?
Cognito: User Pools & Identity Federation
Cognito: User Pools & Identity Federation
API Gateway Bonus: SDK Generation
¡ñ Takes a second to generate
¡ñ Support for multiple languages
¡ð Swift ¡ð Obj C ¡ð Java
¡ð Javascript, and more.
¡ñ Abstracts all the API calling complexity, including session signing
Cognito + IAM + API Gateway = Security [¡Ì]
¡ñ Cognito exchanges your session for temporary IAM credentials with limited permissions
¡ñ The API Gateway generated SDK signs API requests using the SigV4 signing process
¡ð Verify the identity of the requester
¡ð Protect data in transit
¡ð Protect against potential replay attacks
¡ñ Requests are executed with the caller¡¯s credentials
Integrate Cognito into the frontend application.
Now that¡¯s looking a lot more secure!
API Gateway
1. Use Swagger to design your APIs and documentation
2. API Gateway
a. great API management tool
b. seamless integration with Swagger
c. generates SDKs for your API
a. serverless compute service
b. integrates with API Gateway
4. Cognito
a. useful for login workflows
b. outputs temporary IAM credentials with custom permissions
Great, we have an API. What about the frontend?
1. Problems with Monolithic Systems
2. Microservices:ASolution
3. Microservice-drivenAPIs
4. Scaling the Frontend
5. Asynchronous Workflows
S3: More than just storage
¡ñ Host your website on S3 ¡ð HTML, CSS, JS
¡ñ You get:
¡ð 99.999999999% of durability
¡ð 99.99% of availability
¡ñ You pay:
¡ð < $1 per year
Host a static website on S3
One more revision of our stack
Lambda Lambda Lambda
API Gateway
1. You can use S3 to host your frontend
2. S3 hosted websites get out of the box scalability,
availability, and durability
OK, let¡¯s make some money.
You want to sell products through your concierge service.
1. Problems with Monolithic Systems
2. Microservices:ASolution
3. Microservice-drivenAPIs
4. Scaling the Frontend
5. Asynchronous Workflows
Current Checkout API
¡ñ Synchronous ¡ñ Overloaded
¡ð Performs checkout
¡ð Sends notification to user
¡ð (and in a proper implementation, it would also
write to the db)
¡ñ More prone to failure
Asynchronous Checkout
¡ð process credit card transactions asynchronously
¡ð defend against traffic spikes
¡ö 3rd party services are subject to downtime too
¡ð defend against programming errors and bugs
¡ð execute intricate order workflows, without
impacting the user experience
The Asynchronous Toolset
The Asynchronous Toolset
SQS Lambda
The Asynchronous Toolset
SQS Lambda SNS
Setup the Asynchronous Checkout workflow
Another Stack Update
API Gateway
Lambda Lambda Lambda
Asynchronous Order Workflow
1. Remove complex workflows from your APIs
2. Leverage SQS, SNS, and Lambda to distribute your
application
3. Queues and notifications make your system a lot more
resilient to failure
Microservices: Not a Panacea
Monolithic Microservices
THANK YOU!
Ideas for next steps...
1. Integrate a database (ex. DynamoDB) into the system.
a. the database was omitted from the demo to emphasize how you can build a system service by
service, rather than building everything at once
2. Integrate a distributed cache (Memcached or Redis) to store the NLU state between requests.
3. Use Route53 to setup the DNS for your domain.
4. Integrate a real NLP engine and the actual Stripe API to the overall system.
https://aws.amazon.com/s3/
https://aws.amazon.com/iam/
https://aws.amazon.com/lambda/
https://aws.amazon.com/cognito/
https://aws.amazon.com/route53/ http://docs.aws.amazon.com/cognito/latest/developerguide/authentication-flow.html https://aws-de-media.s3.amazonaws.com/images/AWS_Summit_Berlin_2016/session s/pushing_the_boundaries_1300_microservices_on_aws.pdf
https://github.com/mangatanyc/columbia-lecture-concierge
Steps for building the frontend depicted in the demo:
1. download and setup bootstrap template [12.5 min] a. http://getbootstrap.com/examples/cover/#
2. create and integrate FB app [15 min]
a. https://developers.facebook.com/docs/facebook-login/web
3. download and setup chat template [30 min] a. http://codepen.io/supah/pen/jqOBqp
4. create S3 bucket with static website hosting [5 min]
a. http://docs.aws.amazon.com/AmazonS3/latest/dev/HostingWebsiteOnS3Setup.html
5. setup AWS profile using CLI [5 min]
a. http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
6. deploy website to S3 [10 min]
a. build a bash script that leverages the AWS CLI to upload your static files to S3 b. https://github.com/mangatanyc/columbia-lecture-concierge/
7. generate Api Gateway SDK [1 min]
8. integrate Api Gateway SDK [15 min]
a. http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-generate-sdk-javascript.html
9. setup Cognito Identity Pool [5 min]
10. integrate Facebook login with the Identity Pool [15 min]
a. http://docs.aws.amazon.com/cognito/latest/developerguide/facebook.html
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com