Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

Cloud native Microservices using Spring Boot

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Cargando en…3
×

Eche un vistazo a continuación

1 de 51 Anuncio

Más Contenido Relacionado

Presentaciones para usted (20)

Similares a Cloud native Microservices using Spring Boot (20)

Anuncio

Más reciente (20)

Cloud native Microservices using Spring Boot

  1. 1. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Cloud Native Applications Hands on Workshop David Ferreira Pinto <dpinto@pivotal.io> Field Engineering - Pivotal
  2. 2. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. > whoami David Ferreira Pinto
  3. 3. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Agenda • What’s changing? • Implications on applications • help is here! • Workshop • Competition • Deploying and running Cloud Native applications • Wrap up • Pizza & Beers
  4. 4. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. How it used to be User RegistrationCatalog Orders ProfileSearch Recommendation ListsAccount Middleware OS User RegistrationCatalog Orders ProfileSearch Recommendation ListsAccount Middleware OS
  5. 5. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. • Downtime for upgrades • One small change/fix - whole new release • Scalability - vertical/horizontal? • Size for peaks - Crystal ball analysisTM • Snowflakes
  6. 6. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. The world has changed
  7. 7. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. • Distributed computing • Decoupling of components • Latency of communication • Dependencies • Scale as you grow - Size for “now” • Cost efficiencies
  8. 8. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. The rules for the cloud 1. S#!t happens! • assume the worst! 2. See (1) A central truth in cloud computing is that failure is inevitable.  As systems scale, we expect nodes to fail ungracefully in random and unexpected ways, networks to experience sudden partitions, and messages to be dropped at any time. Rather than fight this truth, we embrace it. HEATHER NAKAMA Software Engineer, Azure Search
  9. 9. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. What does this mean for applications? • Scalability • Inter-dependency • Platform dependency • Location dependency • Resiliency/Availability • Traceability
  10. 10. © Copyright 2014 Pivotal. All rights reserved. 10 Scalability Traditional applications have been modeled as monolithic due an easy deployment model Several services are combined into one massive single application This model leads to a poor use of resources when it comes to scaling out your application Greedy components steal resources from others that are collocated with them User RegistrationCatalog Orders ProfileSearch Recommendati on ListsAccount
  11. 11. © Copyright 2014 Pivotal. All rights reserved. 11 . User RegistrationCatalog Orders ProfileSearch Recommendation ListsAccount User RegistrationCatalog Orders ProfileSearch Recommendation ListsAccount User RegistrationCatalog Orders ProfileSearch Recommendation ListsAccount User RegistrationCatalog Orders ProfileSearch Recommendation ListsAccount User RegistrationCatalog Orders ProfileSearch Recommendation ListsAccount
  12. 12. © Copyright 2014 Pivotal. All rights reserved. 12 How you should scale 0 1000000 2000000 3000000 4000000 5000000 6000000 Catalog Search Recommendation Lists Orders Profile User Account Registration Requests Requests
  13. 13. © Copyright 2014 Pivotal. All rights reserved. 13 Inter dependency • Monolithic applications represent component dependency as strong bindings at the code level • It makes harder to get an independent scalable model promoted by service oriented architectures
  14. 14. © Copyright 2014 Pivotal. All rights reserved. 14 Platform specificity import javax.servlet.http.HttpServlet; import com.ibm.servlet.engine.webapp.*; • Hard dependencies on the runtime environment make applications not portable • At code level with runtime dependencies • At OS level (relying on cron as a scheduler)
  15. 15. © Copyright 2014 Pivotal. All rights reserved. 15 Location Specificity : Writing to disk • Applications often need to write to disk, this includes form uploads with binary data, or content in most CMS systems • Containers are short lived and not guaranteed to be executed on the same hardware every time they are needed to restart. Depending on a local file system is a big lock dependency some applications impose on the runtime • Some CMS vendors support usage of a service such as S3 to be the persistent mechanism of choice
  16. 16. © Copyright 2014 Pivotal. All rights reserved. 16 Location Specificity : service locations Cache.hosts=10.68.27.41,10.68.27.4 2 #naming does not help either Cache.hosts=cacheserver1, cacheserver2 Properties file deployed With application
  17. 17. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. 12 factor Apps - 12factor.net 1. Codebase
 One codebase tracked in revision control, many deploys 2. Dependencies
 Explicitly declare and isolate dependencies 3. Config
 Store config in the environment 4. Backing Services
 Treat backing services as attached resources 5. Build, release, run
 Strictly separate build and run stages 6. Processes
 Execute the app as one or more stateless processes 7. Port binding
 Export services via port binding 8. Concurrency
 Scale out via the process model 9. Disposability
 Maximize robustness with fast startup and graceful shutdown 10.Dev/prod parity
 Keep development, staging, and production as similar as possible 11.Logs
 Treat logs as event streams 12.Admin processes
 Run admin/management tasks as one-off processes
  18. 18. © Copyright 2014 Pivotal. All rights reserved. Monolithic Architecture 18 Relational Database Data Access Service HTML JavaScript MVC Service Monolithic ApplicationBrowser
  19. 19. © Copyright 2014 Pivotal. All rights reserved. Microservice Architecture 19 … HTTP HTTP HTTP HTTP HTTP HTTP AMQP AMQP Relational DB Key/Value Store Graph DB
  20. 20. © Copyright 2014 Pivotal. All rights reserved. 20 Microservice Architectures • Modularity Based on Component Services • Change Cycles Decoupled / Enable Frequent Deploys • Efficient Scaling • Individual Components Less Intimidating to New Developers • Enables Scaling of Development • Eliminates Long-Term Commitment to Technical Stack
  21. 21. © Copyright 2014 Pivotal. All rights reserved. Organize Around Business Capabilities 21 Data Access Service HTML JavaScript MVC Service UISpecialists Middleware Specialists DBAs BusinessCapability BusinessCapability BusinessCapability Siloed Functional Teams http://martinfowler.com/articles/microservices.html#OrganizedAroundBusinessCapabilities Siloed Application Architectures Cross- functional Teams Microservice Architectures
  22. 22. ‹#›© 2015 Pivotal Software, Inc. All rights reserved. • Manage Configuration Data provided to µServices via the environment reliably?(Factor-3) • Update Configuration Data to all µServices instances simultaneously? • Ensure µServices can discover each other, despite being Disposable? (Factor-9) • Handle load-balancing between µServices of the same type? (Factor-8) • Guard against cascading failures when all instances of the same µService fail? • Ensure resiliency by restoring failed µServices? 12 factors is not enough, Distributed Systems are hard!!! HOW DO WE:
  23. 23. ‹#›© 2015 Pivotal Software, Inc. All rights reserved. Help is Here! Spring Cloud Quickly add Distributed Systems Patterns to your µServices with Pivotal Cloud Foundry Keeps your µServices running!
  24. 24. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Service registry & discovery - Eureka
  25. 25. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Service registry & discovery - Eureka @SpringBootApplication @EnableEurekaServer //@EnableDiscoveryClient public class RegistryApplication { public static void main(String[] args) { SpringApplication.run(RegistryApplication.class, args); } }
  26. 26. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Client-side load balancing - Ribbon
  27. 27. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Client-side load balancing - Ribbon @Autowired @LoadBalanced private RestTemplate restTemplate; Quote quote = restTemplate.getForObject("http://quotes/quote/ {symbol}", Quote.class, symbol);
  28. 28. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Circuit Breaker - Hystrix
  29. 29. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Circuit Breaker - Hystrix @HystrixCommand(fallbackMethod = "getCompaniesFallback") public List<CompanyInfo> getCompanies(String name) { CompanyInfo[] infos = restTemplate.getForObject("http://quotes/company/ {name}", CompanyInfo[].class, name); return Arrays.asList(infos); } private List<CompanyInfo> getCompaniesFallback(String name) { List<CompanyInfo> infos = new ArrayList<>(); return infos; }
  30. 30. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Configuration Server
  31. 31. ‹#›© 2015 Pivotal Software, Inc. All rights reserved. Spring Cloud Services for PCF https://network.pivotal.io/products/p-spring-cloud-services
  32. 32. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Workshop
  33. 33. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Spring Trader Application
  34. 34. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. • Services: • Quotes service • Accounts service • Portfolio service • Web service Spring Trader Application http://bit.ly/1RLHzXQ or https://github.com/dpinto-pivotal/cf-SpringBootTrader Quotes AccountsPortfolio Web DB DB Discovery Service Circuit Breaker Dashboard
  35. 35. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Competition • Make the most money!!! • Create account with 100,000 • Buy and sell as much as you want. • When I say so, sell everything! • Highest account balance wins!
  36. 36. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Setup • You will need some tools (lab 1). • If you don’t want to install tools on your laptop, we have a VM you can use.
  37. 37. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Exercises • Deploy applications to Cloud Foundry 1. Set up the environment 2. Deploy the registry service 3. Create a user-provided service 4. Deploy quote microservice 5. Deploy all services at one 6. Scaling applications 7. Zero downtime deployments 8. Application Performance Monitoring
  38. 38. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Lab 1: Set up the environment • Goal is to ensure you have all the tools and accounts to run through the rest of the exercises. • Java 8 • git CLI — install git cli (or other git tool that allows you to clone repo) — clone the repository locally. • CF CLI — install CF CLI to allow you to interact with PCF • Build code - ./gradlew build - could take sometime…
  39. 39. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Lab 1: Login to Pivotal Cloud Foundry • Login to Pivotal’s test environment • cf login -a api.emea.fe.pivotal.io • user: PodX • Password: PodX • browser: http://console.emea.fe.pivotal.io
  40. 40. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Lab 2 & 3: Create the Services • Create a service called: discovery-service • bind it to your space • Create a service called: circuit-breaker-dashboard • bind it to your space
  41. 41. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. And you may as well…. • Create a service called: traderdb • bind it to your space • Can be any RDBMS ie. Postgres, ClearDB, etc.
  42. 42. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Lab 4 & 5: Pushing micro services • cf push -f manifest-quotes.yml • And same for accounts, portfolio and web.
  43. 43. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Competition Buy shares!!!!
  44. 44. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Lab 6: Scaling the services • cf scale quotes -i 2 • yes it is that simple!!! • What happens when you scale the other services? • is there one that behaves differently? • How can we solve this?
  45. 45. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Lab 7: Zero downtime deployments • edit manifest-quote.yml • cf push -f manifest- quote.yml • What happens in Discovery Service dashboard? --- timeout: 180 instances: 1 memory: 330M env: SPRING_PROFILES_DEFAULT: cloud JAVA_OPTS: -Djava.security.egd=file:///dev/urandom applications: - name: quotes-2 random-route: true path: springboottrades-quotes/build/libs/quotes-0.2.jar services: [ discovery-service ]
  46. 46. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Lab 8: Application Performance Monitoring • Go To Marketplace • Create new relic service and bind it to app • Re-Push the apps • In your App Manager UI, accept the license. • wait a few minutes • check newrelic dashboard.
  47. 47. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. And the winner is….
  48. 48. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Wrap up
  49. 49. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. Summary • It’s a different world! • decoupling of application and infrastructure processes • decoupling of application components • Platform to automate the running of applications • Framework to simplify development of cloud applications
  50. 50. ‹#›© 2014 Pivotal Software, Inc. All rights reserved. What’s next? • Topics for future meetups? • What would you like to hear/discuss? • Examples: • Drill down into each cloud service e.g. Circuit Breaker • API management • Continuous Delivery • Logging/Monitoring • APM • Any presenters? • Format? • Time?

×