Back your app with MySQL and Redis on Cloud Foundry

38
Unless otherwise indicated, these slides are © 2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Back your App with MySQL & Redis, the Cloud Foundry Way Kenny Bastani , Spring Developer Advocate, Pivotal @ kennybastani

Transcript of Back your app with MySQL and Redis on Cloud Foundry

Page 1: Back your app with MySQL and Redis on Cloud Foundry

Unless otherwise indicated, these slides are © 2016 Pivotal Software, Inc. and licensed under aCreative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/

Back your App with MySQL & Redis, the Cloud Foundry Way

Kenny Bastani, Spring Developer Advocate, Pivotal @kennybastani

Page 2: Back your app with MySQL and Redis on Cloud Foundry

Speaker Intro - Kenny Bastani

2

Page 3: Back your app with MySQL and Redis on Cloud Foundry

What are we talking about today?

! Spring Data Redis

! Spring Boot

! We’re going to build a Spring Boot web service with MySQL storage

! Add in Redis caching with Spring Data Redis

! Deploy to the cloud! (Cloud Foundry)

! Stream metrics and compare caching vs. no caching

3

Page 4: Back your app with MySQL and Redis on Cloud Foundry

But first…

A database joke

4

Page 5: Back your app with MySQL and Redis on Cloud Foundry

Why did the database have problems ingesting data?

5

Page 6: Back your app with MySQL and Redis on Cloud Foundry

Because it had ACID indigestion

6

Why did the database have problems ingesting data?

Page 7: Back your app with MySQL and Redis on Cloud Foundry

Ok let’s get serious

Let’s talk about architecture

7

Page 8: Back your app with MySQL and Redis on Cloud Foundry

Microservices & Polyglot PersistenceIf you’re into that kind of thing

8

Page 9: Back your app with MySQL and Redis on Cloud Foundry

Polyglot Persistence

9

Page 10: Back your app with MySQL and Redis on Cloud Foundry

Spring Data Redis

10

Page 11: Back your app with MySQL and Redis on Cloud Foundry

What is Spring Data Redis?

! Easy access to Redis from your Spring applications

! Provides a variety of abstractions for you to interact with Redis

• Spring Data Repositories (NEW!)

• RedisTemplate

• CacheManager

! Available as a Spring Boot starter project from http://start.spring.io

! Provides a CacheManager implementation so you can use annotation-driven caching on methods

11

+

Page 12: Back your app with MySQL and Redis on Cloud Foundry

How does Spring Data work?

Abstractions…

12

Page 13: Back your app with MySQL and Redis on Cloud Foundry

Cloud Native Application with Redis Caching

13

Page 14: Back your app with MySQL and Redis on Cloud Foundry

Spring BootA JVM micro-framework for building microservices

14

Page 15: Back your app with MySQL and Redis on Cloud Foundry

What is Spring Boot?

15

Page 16: Back your app with MySQL and Redis on Cloud Foundry

Spring Initializr

16

supports rapid development of production-ready applications and services

Bootstrap your application

Page 17: Back your app with MySQL and Redis on Cloud Foundry

17

Page 18: Back your app with MySQL and Redis on Cloud Foundry

Add Redis CachingConfigure Redis connection and Spring Data cache manager

18

Page 19: Back your app with MySQL and Redis on Cloud Foundry

Redis Cache Config

19

Page 20: Back your app with MySQL and Redis on Cloud Foundry

Configure Redis Connection

20

Page 21: Back your app with MySQL and Redis on Cloud Foundry

Configure Redis Template

21

Page 22: Back your app with MySQL and Redis on Cloud Foundry

Configure Redis Cache Manager

22

Page 23: Back your app with MySQL and Redis on Cloud Foundry

Annotation-driven Caching

23

Page 24: Back your app with MySQL and Redis on Cloud Foundry

Manage Users REST API Contract

24

Page 25: Back your app with MySQL and Redis on Cloud Foundry

Create a UserService

25

Page 26: Back your app with MySQL and Redis on Cloud Foundry

@Cacheable - Get or put

26

Page 27: Back your app with MySQL and Redis on Cloud Foundry

@CachePut - Update

27

Page 28: Back your app with MySQL and Redis on Cloud Foundry

@CacheEvict - Invalidate record

28

Page 29: Back your app with MySQL and Redis on Cloud Foundry

Deploy to the cloud!Using Cloud Foundry

29

Page 30: Back your app with MySQL and Redis on Cloud Foundry

Cloud Foundry

! Open-source platform as a service (PaaS)

! Supports multiple cloud providers

! Supports build packs for multiple application frameworks

! Supports Linux container deployments using Diego

! Supports Docker container registries

30

Page 31: Back your app with MySQL and Redis on Cloud Foundry

Application Server vs Linux Container deployments

31

Page 32: Back your app with MySQL and Redis on Cloud Foundry

Application Server Deployment

! Load balancing requires provisioning of new VMs and app server installations

! Poor resource isolation; memory leaks can cause other applications to become unavailable

! Runtime environment is driven by the operator

32

Virtual Machine

App

Linux Kernel

App App

Hardware Infrastructure

Page 33: Back your app with MySQL and Redis on Cloud Foundry

Linux Container Deployment

! Development team drives the application runtime of a container

! Containers are resource isolated, allowing efficient scheduling onto a grid of VMs

! Containers take seconds to start, VMs take minutes

! It’s not a rule that there is one microservice per container

33

Virtual Machine

Container

Linux Kernel

App App

App App

ContainerApp App

App App

ContainerApp App

App App

Hardware Infrastructure

Page 34: Back your app with MySQL and Redis on Cloud Foundry

Microservices - Container Deployment

! Each microservice can be containerized with their application dependencies

! Containers get scheduled on virtual machines with an allotted resource policy

34

Page 35: Back your app with MySQL and Redis on Cloud Foundry

Auto-scaling

! Minutes to start a VM, but seconds to start a container

! An elastic runtime handles auto-scaling of VMs with cloud providers

35

Page 36: Back your app with MySQL and Redis on Cloud Foundry

Demo CF deployment

run.pivotal.io

36

Page 37: Back your app with MySQL and Redis on Cloud Foundry

37

Page 38: Back your app with MySQL and Redis on Cloud Foundry

38

Learn More. Stay Connected.

! Twitter: @kennybastani

! Spring: spring.io/team/kbastani

! Blog: kennybastani.com

! GitHub: github.com/kbastani

Twitter: twitter.com/springcentral

YouTube: spring.io/video

LinkedIn: spring.io/linkedin

Google Plus: spring.io/gplus