Microservices & Serverless - clnv.s3.amazonaws.com · Why Microservices? … and when! Applying...
-
Upload
nguyentruc -
Category
Documents
-
view
232 -
download
0
Transcript of Microservices & Serverless - clnv.s3.amazonaws.com · Why Microservices? … and when! Applying...
Microservices & Serverless architecture principles applied
Stève Sfartz, API Evangelist @[email protected]
DEVNET-1871
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Cisco Spark
Questions? Use Cisco Spark to communicate with the speaker after the session
1. Find this session in the Cisco Live Mobile App
2. Click “Join the Discussion”
3. Install Spark or go directly to the space
4. Enter messages/questions in the space
How
cs.co/ciscolivebot#DEVNET-1871
Why Microservices? … and when!
Applying Twelve Factors
Applying Microservices Design principles
Demos, demos, demos
Microservices & Serverlessarchitecture principles applied
Why Microservices? … and when!
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Microservices (2014)Martin Fowler, James Lewis
In short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API.
These services are built around business capabilities and independently deployable by fully automated deployment machinery.
There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.
DEVNET-1871 6
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Monolithic versus Microserviceshttp://martinfowler.com/articles/microservices.html
DEVNET-1871 7
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
the Monolithic style
• An application built as a single unit, 3 main parts
• a client-side user interface ,
• a database
• and a server-side application that handles HTTP requests, execute domain logic, retrieve and update data from the database, and select and populate HTML views to be sent to the browser.
• This server-side application is a monolith
• a single logical executable
• any change requires building and deploying a new version
• Locally built and tested on devs’ machines
• CI/CD pipeline to secure production
8DEVNET-1871
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
scaling the Monolith
• Several instances behind a load balancer
• lack of modularity
DEVNET-1871 9
Load Balancer
Monolith
ClientClient
Client
- Routing traffic complexity
- Very large code base
- Change cycles tied together
- Limited scalability
+ Quickest path to scale
+ High availability
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
making the Monolith more modular
• Specialized instances of a single codebase
• Modular invocation
DEVNET-1871 10
Load BalancerReal time
business logic
ClientClient
Client
MonolithMonolithAuthentication
MonolithBatches
Load Balancer
‘Renovation’ as an alternative to a rewrite
Generally does the trick
BONUS: engage an iterative « API »-fication
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
The End of Monoliths ?
DEVNET-1871 11
http://www.stavros.io/posts/microservices-cargo-cult/
Applying Twelve Factors
for developers building apps which run as a service
for ops engineers who deploy or manage such apps
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 13DEVNET-1871
Twelve Factorshttps://12factor.net/
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 14DEVNET-1871
Twelve factors applied to Spark Botshttps://github.com/CiscoDevNet/botkit-template/blob/master/bot.js#L49
Twelve factors applied to Spark Bots
« One code base to rule them all »
- on your local machine
https://github.com/CiscoDevNet/botkit-template
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
The ‘config file’ versus ‘env variables’ dilemna
• Where to put all not env specific info, nevertheless configurable
• Think defaults for PORTS, HTTP ROUTES, INSTANCE NAME
• Common practice to use a ‘.env’ file to load variables to ENV when your code launches
• Ruby: https://github.com/bkeepers/dotenv
• Node: https://github.com/motdotla/dotenv
• ALWAYS read from ENV and assume env variables precedence
• over-ride defaults, the execution environment always has the last world
• env may be injected by CI/CD tools, your Cloud Platform or Docker Orchestrator
• environment managed by Puppet or Chef
• ‘heroku config’ CLI command, and console environment
• env field in a Kubernetes Pod YAML configuration
16DEVNET-1871
Twelve factors applied to Spark Bots
« One code base to rule them all »
- on Heroku- on Glitch
https://github.com/CiscoDevNet/botkit-template
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Twelve Factor Sumpup
• Take time to iterate on your code’s startup to read from environments
• Local dev machines, integration, demo env, production
• When appropriate, dig into each platform specifics
• Enter ops feedbacks as new requirements / add to your backlog
• Logs
• Healthchecks
18DEVNET-1871
Applying Microservices design principles
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Monolithic versus Microserviceshttp://martinfowler.com/articles/microservices.html
DEVNET-1871 20
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Common Characteristics
Componentization via Services
Organized around Business Capabilities
Products not Projects
Smart endpoints and dumb pipes
Decentralized governance
Decentralized data management
Infrastructure automation
Design for failure
Evolutionary design
http://martinfowler.com/articles/microservices.html
DEVNET-1871 21
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Organized around Business Capabilities
Any organization that
designs a system will
produce a design
whose structure is a
copy of the
organization's
communication
structure.
Melvyn Conway,
1967.
DEVNET-1871 22
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Organized around Business Capabilities
Microservices to solve Conway’s anti-pattern
Cross-functional teams…. … organised around capabilities
DEVNET-1871 23
Event bot
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Componentization via Services
Services as components rather than libraries
Services avoid tight coupling by using explicit remote call mechanisms.
Services are independently deployable and scalable
DEVNET-1871 25
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 26DEVNET-1871
Componentization via Serviceshttps://creations.devnetcloud.com/detail?cid=1e4a9f92-deea-11e7-9d2f-aed03b187700
Events API
Bot AdminPublic
catalog
https://devnet-events-api.herokuapp.com/
CiscoDevNet
@sparkbot.io Postman JSON
Voice
Responder
Tropo
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Smart endpoints and dumb pipes
Be as decoupled and as cohesive as possible
own domain logic,
act more as filters in the classical Unix sense
using simple RESTish protocols and lightweight messaging
Smarts live in the services, not in-between the endpoints
No central tool / bus that includes sophisticated routing, transformations, process, business rules
Pre-requisite : turn the chatty in-process communication of the monolith into coarser-grained network messaging
DEVNET-1871 27
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 28DEVNET-1871
Componentization via Services
Think API first = 1 microservice
Treat each API consumer as a new independent channel = multiples consumers
Design Best Practices
deployment
delivery
versioning
contracts
scaling/autoscaling
service discovery
load balancing
routing / adaptive routing
health checking
configuration
circuit breaking
TTL/deadlining
latency tracing
service causal tracing
distributed logging
metrics exposure, collection
Adaptive Routing
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
When 1 backend becomes latent
DEVNET-1871 30
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco PublicDEVNET-1871
At 50+ req/s, all request threads can block in seconds
31
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
NetFlix Hystrix
• Latency and Fault Tolerance library
• designed to isolate points of access to remote systems, services and 3rd party libraries,
• stop cascading failure and enable resilience where failure is inevitable.
• real time monitoring via Dashboard
DEVNET-1871 32
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco PublicDEVNET-1871
Hystrix Dashboard
33
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Healthcheck
• Passive healthcheck
• Automated from analysis of your app responses (ie, check status codes)
• Active healthcheck
• Basically GET / returns a 200 OK
• Provide extra JSON meaning full data
• Used for monitoring, diagnose but also traffic optimization
• Platform dependant: Nginx active healthckech, Amazon LB healthcheck configuration, Kubernetes liveness probes, Envy
• Types of failture: 50x
• Include Maintenance, Recovery states
34DEVNET-1871
Botkit template Healthcheck
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 36DEVNET-1871
Healthcheck
• Always provide an healthcheck
• You cannot assume how your service will be deployed
• Make it configurable
• ON / OFF, credentials
• Provide extra JSON meaning full data
• Include Maintenance, Recovery states
• Documentation
• Start small with 200, think big via adapters to address various platforms
• Nginx active healthckech, Amazon LB healthcheck configuration, Kubernetes liveness probes, Envyo healthckeck
• FAIL FAST (twelve factor)
Best practices
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Resources
• Amazon healthcheck configuration
• https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-healthchecks.html
• Nginx active healthecks
• https://www.nginx.com/resources/admin-guide/http-health-check/#hc_active
• Kubernetess Livenessprobes
• https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes
• Envoy
• https://istio.io/docs/concepts/what-is-istio/overview.html#envoy
37DEVNET-1871
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Common Characteristics
Componentization via Services
Organized around Business Capabilities
Products not Projects
Smart endpoints and dumb pipes
Decentralized governance
Decentralized data management
Infrastructure automation
Design for failure
Evolutionary design
http://martinfowler.com/articles/microservices.html
DEVNET-1871 38
‘Sidecar’ pattern
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
SideCar
• Complement an existing service with extra capabilities via a distinct service rather than in-process
• Ex: SSL endpoint, outgress routing, traffic priorization
• Typically reverse proxy
• Or smart routing
40DEVNET-1871
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Caddy Web Server
• Production-ready
• Secure by default: HTTPS by default, hardened TLS stack
• Written in go, self-contained
• Single executable with no dependency
• https://caddyserver.com/download
• Multi-platform, container friendly
• Plugin-architecture
41DEVNET-1871
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 42DEVNET-1871
Spark Widgets
• Caddyfile
Supports Spark Calls over HTTPS
https://github.com/CiscoDevNet/widget-samples
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Resources
• Caddy
• https://caddyserver.com/
• Cisco Spark Widget Samples
• https://github.com/CiscoDevNet/widget-samples
• Spark Affinity: scaling Webhooks
• https://github.com/ObjectIsAdvantag/spark-webhook-affinity
43DEVNET-1871
Programmable API Gateways
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco PublicDEVNET-1871
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 46DEVNET-1871
Kong
• Opensource API Gateway
• Microservices Management building block
• Set of nginx plugins
• Opensource
• Cluster configuration: persists data to Cassandra or PostgreSQL
https://getkong.org/
Kong
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 48DEVNET-1871
Kong: launching with dockerPostGreSQL backend
docker run -d --name kong-database -p 5432:5432
-e "POSTGRES_USER=kong" -e "POSTGRES_DB=kong" postgres:9.4
docker run --rm --link kong-database:kong-database
-e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=kong-database"
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database"
kong:latest kong migrations up
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 49DEVNET-1871
Kong: launching with dockerReverse proxy
docker run -d --name kong --link kong-database:kong-database
-e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=kong-database"
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database"
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout"
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout"
-e "KONG_PROXY_ERROR_LOG=/dev/stderr"
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr"
-p 8000:8000 -p 8001:8001 kong:latest
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 50DEVNET-1871
Kong: launching with docker
• Proxy at port :8000
• Administration at :8001
• Expose :8443 and :8444 for SSL support
• Healthcheck at admin root :8001/, :8444/
Reverse proxy
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 51DEVNET-1871
Kong: Registering HTTP Endpoint
curl -i -X POST --url http://localhost:8001/apis/
--data 'name=minispark'
--data 'uris=/minispark'
--data 'upstream_url=https://mini-spark.herokuapp.com/'
Via admin API
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 52DEVNET-1871
Kong: Rate Limitation
curl -X POST http://localhost:8001/apis/minispark/plugins
--data "name=rate-limiting"
--data "config.minute=5"
--data "config.limit_by=credential"
https://getkong.org/plugins/rate-limiting/
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Resources
• Kong
• https://getkong.org
• Tyk
• https://tyk.io
• Envoy
• https://www.envoyproxy.io
• Ambassador
• https://www.getambassador.io
53DEVNET-1871
Wrapup
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 55DEVNET-1871
Wrapup
• Make your code easy to run and scale
• Embrace environment variables and configuration best practices
• Docker-ready, Kubernetes-ready
• Leverage the infrastructure, don’t ignore it !!!
• Get familiar with Load Balancers, Reverse Proxies, API Gateways
• Use for local testing, demonstration environments
• Expose healthchecks
Applying Microservices Principles as an Application Developer
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 56DEVNET-1871
Wrapup: other considerations
• Solid communications
• Fault tolerant pipes
• Gateways and Service discovery
• Committed teams
• Devops culture
• Code/Test/Deploy/Support, 24/7
• Automation, automation, automation
• Ownership
• Organisation aligned with the overall strategy
• Operational insights (monitoring, logging infrastructure, real time analysis)
Lessons learnt from Microservices journeys
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Cisco Spark
Questions? Use Cisco Spark to communicate with the speaker after the session
1. Find this session in the Cisco Live Mobile App
2. Click “Join the Discussion”
3. Install Spark or go directly to the space
4. Enter messages/questions in the space
How
cs.co/ciscolivebot#DEVNET-1871
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
• Please complete your Online Session Evaluations after each session
• Complete 4 Session Evaluations & the Overall Conference Evaluation (available from Thursday) to receive your Cisco Live T-shirt
• All surveys can be completed via the Cisco Live Mobile App or the Communication Stations
Don’t forget: Cisco Live sessions will be available for viewing on-demand after the event at www.ciscolive.com/global/on-demand-library/.
Complete Your Online Session Evaluation
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public
Continue Your Education
• Demos in the Cisco campus
• Walk-in Self-Paced Labs
• Tech Circle
• Meet the Engineer 1:1 meetings
• Related sessions
DEVNET-1871 59
Thank you