Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Microservices & API Gateways

5,385 views

Published on

How API Gateways are becoming increasing popular in efficiently managing and orchestrating microservices at scale - a new pattern emerged.

Published in: Technology
  • Be the first to comment

Microservices & API Gateways

  1. 1. Microservices & API Gateways Marco Palladino
  2. 2. #nginx #nginxconf2 I am Marco Palladino CTO at mashape.com Core committer at github.com/Mashape/kong
  3. 3. #nginx #nginxconf3 Monolitich vs Microservices Pros and Cons API Gateway Pattern With real world use-cases Kong + NGINX For API Management Topics
  4. 4. #nginx #nginxconf4 Monolithic Architecture Client LB Customers Orders Invoices Customers Orders Invoices Database Schema
  5. 5. #nginx #nginxconf5 Monolithic Application Pros/Cons Simplicity, for small codebases Faster early development speed Easy testing IDE support Not ideal for growing codebases Slower iterations in the long term Harder to innovate Steep code learning curve
  6. 6. #nginx #nginxconf6 Microservice-oriented architecture Client LB Customers Orders Invoices LB LB Customers Orders Invoices DB Schema DB Schema DB Schema Event Handler + Workers
  7. 7. #nginx #nginxconf7 Microservice-oriented Application Pros/Cons Better architecture for large applications Better agility in the long term Microservices: easy to learn Isolation for scalability and damage control More moving parts Complex infrastructure requirements Consistency and availability Harder to test
  8. 8. #nginx #nginxconf8 Why an API Gateway? API Gateway Microservices
  9. 9. #nginx #nginxconf9 API Gateway Pattern Client LB Customers Orders Invoices LB LB Customers Orders Invoices DB Schema DB Schema DB Schema API Gateway • Optimized endpoints • Request collapsing • And more
  10. 10. #nginx #nginxconf10 Optimized Endpoints Client LB Customers Orders Invoices LB LB Customers Orders Invoices API Gateway { "id": "cus_123", "customer_name": "Bob", "address": "500 Montgomery St, SF" } { "id": "order_123", "customer_id": "cus_123", "item_name": "Vacuum Cleaner" } { "order_id": "order_123", "price": "99.99" } GET /customers/{id} { "customer_id": "cus_123", "name": "Bob", "address": "500 Montgomery St, SF", "orders": […], "invoices": […], } + extra transformations
  11. 11. #nginx #nginxconf11 Centralized Middleware Functionality Client Public APIs Private APIs Partner APIs API Gateway • Authentication • Security • Traffic Control • Ops • Logging • Transformations • Etc Available to everybody Only for internal usage Only for specific partners FaaS AWS Lambda, etc
  12. 12. #nginx #nginxconf12 Ops: Blue/Green deployments customers.service 1.0.0 customer.service 1.0.1 API Gateway ALL TRAFFIC NO TRAFFIC customers.service 1.0.0 customer.service 1.0.1 API Gateway ALL TRAFFIC NO TRAFFIC
  13. 13. #nginx #nginxconf13 Ops: Canary Releases customers.service 1.0.0 customer.service 1.0.1 API Gateway 100% TRAFFIC 0% TRAFFIC customers.service 1.0.0 customer.service 1.0.1 API Gateway 90% TRAFFIC 10% TRAFFIC
  14. 14. #nginx #nginxconf14 Ops: Load Balancing Client OrdersLB CustomersAPI Gateway Client Orders CustomersAPI Gateway Client Orders CustomersAPI Gateway Service Discovery • etcd • consul 1. 2. 3.
  15. 15. #nginx #nginxconf15 Ops: Circuit Breakers Client Orders OrdersAPI Gateway Orders Invoices Orders Customers Too many 50x errors
  16. 16. Building a microservice != Running a microservice
  17. 17. #nginx #nginxconf17
  18. 18. #nginx #nginxconf18 API Gateways, and Kong, can help Microservice MicroserviceMicroservice Client • Authentication • Security • Traffic Control • Ops • Logging • Transformations • Etc • API for Automation • On-boarding • Developer Portal
  19. 19. #nginx #nginxconf What is Kong? Kong is an open-source management layer for APIs to secure, manage and extend APIs and Microservices. https://getkong.org
  20. 20. #nginx #nginxconf What is Kong? Built on top of NGINX, centralizes common middleware functionality:
  21. 21. #nginx #nginxconf Kong Plugins Can be created from scratch & extended by the community.
  22. 22. #nginx #nginxconf Kong: OpenResty + NGINX NGINX OpenResty Clustering & Datastore Plugins RESTful Administration API • JSON HTTP API • Extendable by Plugins • Can be integrated for automation • Plugins created with LUA • Intercept Request/Response lifecycle • Can integrate with third-party services • Either Cassandra or PostgreSQL • Optionally Redis for some plugins • Single or multi-DC clustering • Underlying engine of Kong • Provides hooks for Req/Res lifecycle • Extends underlying NGINX • The core dependency • Handles low-level operations • Solid foundation and known tech
  23. 23. #nginx #nginxconf NGINX Configuration worker_processes auto; daemon on; pid pids/nginx.pid; error_log logs/error.log notice; worker_rlimit_nofile 4864; events { worker_connections 4864; multi_accept on; } http { include 'nginx-kong.conf'; } init_by_lua_block { .. } init_worker_by_lua_block { .. } server { listen 0.0.0.0:8000; location / { access_by_lua_block { .. } header_filter_by_lua_block { .. } body_filter_by_lua_block { .. } log_by_lua_block { .. } } } ..nginx.conf nginx-kong.conf
  24. 24. #nginx #nginxconf Kong Entry-points $ curl 127.0.0.1:8000 $ curl 127.0.0.1:8443 $ curl 127.0.0.1:8001 Proxy Admin API
  25. 25. #nginx #nginxconf Core Entities $ curl 127.0.0.1:8001/apis $ curl 127.0.0.1:8001/consumers $ curl 127.0.0.1:8001/plugins
  26. 26. #nginx #nginxconf Plugins Configuration Matrix 1. Per every API and every Consumer 2. Per every API and a specific Consumer 3. Per a specific API and every Consumer 4. Per a specific API and a specific Consumer
  27. 27. #nginx #nginxconf Multi-DC deployment DC1 KONG C* API API API API API API KONG C* DC2 KONGC* API API API API API API KONGC* • Horizontal Scalability • Cassandra or PostgreSQL • Clients can be both internal and external Client Client Invalidation events Data
  28. 28. Demo Time
  29. 29. #nginx #nginxconf Thank You 29 getkong.org linkedin.com/marcopalladino @thefosk mashape.com

×