SpringIO 2016 - Spring Cloud MicroServices, a journey inside a financial entity

37
Spring Cloud Microservices A journey inside a financial entity Jordi Gil @jordigilnieto Toni Jara @tonijar

Transcript of SpringIO 2016 - Spring Cloud MicroServices, a journey inside a financial entity

Spring Cloud Microservices

A journey inside a financial entity Jordi Gil @jordigilnieto

Toni Jara @tonijar

Preface

Team

Spring I/O

2016

Toni Jara

Software engineer with more than 10 years of experience

involved in complex architecture projects as Technical Team

Lead and Senior Architect.

With more than 8 years of experience working with Spring

(mainly Core Framework, MVC and Webflow), lately he’s

been working on microservices architectures with Spring

Cloud.

Jordi Gil

Jordi is a Software Architect with over 18 years of experience

in application development, mainly in information systems for

banking and insurance industries. He focuses on the definition

of architectures for heterogeneous environments and with high

performance, interoperability and availability requirements.

In everis he is leading the innovation group where new

technologies, patterns and architecture models are assessed

for applicability in final customers.

Currently his main areas of interest are MicroServices

Architectures and Cloud PaaS platforms.

Index

1. Introduction

2. Development

3. Deployment

4. Operations

5. Demo

6. Conclusions

7. Questions

Spring I/O

2016

Spring I/O

2016

INTRODUCTION

Introduction

Objectives

Spring I/O

2016

Microservices

Introduction

Monolithic applications

Spring I/O

2016

• Easy to Develop & Deploy & Scale

• Can Be Intimidating to New

Developers

• Modularity Dependent Upon

Language / Frameworks

• Change Cycles Tightly Coupled /

Obstacle to Frequent Deploys

• Inefficient Scaling

• Obstacle to Scaling Development

• Requires Long-Term Commitment to

Technical Stack

HTML JavaScript MVC

Service Service

Data Access

Browser

Relational

Database

Monolithic Application

Introduction

Monolithic applications 2.0

Spring I/O

2016

• SOA approach

• ESBs used to integrate monolithic

applications

• ESB Tightly Couples Services

• Centralized governance models that

actively inhibit change

• ESB becomes the biggest monolith

Service Service

SOA - ESB

Service Service Service

Service Service

Introduction

Microservices architecture

Spring I/O

2016

• 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

• Complexity associated to distributed

systems

• Operational burden

API

Service

Storage

Microservice 1

API

Service

Storage

Microservice 2

API

Service

Storage

Microservice 3

API

Service

Storage

Microservice 4

Introduction

Microservices in a bank

Spring I/O

2016

• API Gateway as the single entry

point for all clients

• Critical core business services

managed through SOA model

• Backends accessed exclusively

through Business Services

API Gateway

Front App Front App

Mainframe

Business Service Business Service

Backends

Business Services - SOA

Microservices

Introduction

Challenges

Spring I/O

2016

Discovery /

Reuse

Scope definition

Productivity

Homogenization

Versioning

Integration

Messaging

formats

Error

management

Testing

Distributed

tracing

Service

Discovery

Load Balancing

Fault Tolerance Centralized

Configuration

Dynamic

Routing

API Gateway

Technical

challenges

derived from

implementing

distributed

systems

Challenges

derived from

enterprise

environment

Spring Cloud

Procedures &

custom

components

Enterprise-ready

framework

Introduction

Technical model

Spring I/O

2016

Operation

Sp

rin

g C

lou

d

Infrastructure services

Sp

rin

g C

lou

d

Service Registry

Eureka

Server

Configuration

Config

Server

Git

Service execution framework

Sp

rin

g C

lou

d

Sp

rin

g B

oo

t

Service

Discovery

Eureka

Client

Fault Tolerance /

Resilience

Hyxtrix

Load Balancer

Feign

Security

Spring Cloud

Security

Embedded

servlet container

Tomcat, Jetty,

Undertow

Monitoring &

Management

Actuator

Endpoints

IPC – Inter Process Communication

Runtime Gateway

Zuul

Monitoring

Dashboard

Hystrix +

Turbine

Log

Management

Central logging

Microservices

SOA

Integration

Database

Core

Messages

Error mgmt

Config

Audit &

Log

HTTP

cache

Introduction

Lifecycle

Spring I/O

2016

Discovery

• Repositories

Design

• Scope definition

Build

• Tools

• Scaffolding

• Patterns

• Naming conventions

• Core frameworks

• Integrations

QA

• Testing frameworks

• Mocking

• Code quality

Deployment

• Environment topology

• Procedures

Operations

• Central Audit & Logging

• Monitoring

• Administration

Spring I/O

2016

DEVELOPMENT

Development

Discovery

Spring I/O

2016

API

Service

Storage

Microservice

API Documentation

in Swagger format

Model

metadata

Operation

metadata

Configuration

Springfox

library

Managed by application

Managed by

framework

API Repository

Discovery

Subscription

Impact analysis

Audit

Discovery Design Build QA Deployment Operations

Development

Design

Spring I/O

2016

• Key aspect for building a successful microservices architecture.

• No Silver Bullet, but some techniques may help…

Business

Area

Business

Domain

Service

Domain

Existing reference architectures in some industries

– Banking – BIAN (Banking Industry Architecture

Network)

– Insurance - Acord

Functional decomposition based on Verbs (e.g. Checkout) or Nouns (e.g. Product) of

your application RESTful APIs

Domain Driven Design divides a complex domain up

into multiple bounded contexts and maps out the

relationships between them.

Discovery Design Build QA Deployment Operations

Development

Build tools

Spring I/O

2016

IDE

Source code management

GIT / SVN

Lifecycle automations

Apache Maven

Testing

Unit testing Code

Coverage

Code quality

Findbugs PMD Checkstyle SonarQube

To increase productivity, it’s very important to define a standard tool set.

Find the essential tools and plugins hierarchy below:

Discovery Design Build QA Deployment Operations

Development

Source code management tools

Spring I/O

2016

Discovery Design Build QA Deployment Operations

Source code management with Atlassian Bitbucket

(GIT):

• One project for each team

• One repository for each Microservice

• Collaborative development and revisions with pull

requests & merges (Gitflow)

Master Official version

Hotfix Official fixings

Develop Integration

Feature Functionality

Release Candidate version

Gitflow documentation: https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

Development

Maven archetype

Spring I/O

2016

Maven archetype

Java sources & tests

Maven Dependencies

Config files Basic project

structure

Naming conventions

• Internal and external core dependencies

Starter parent (POM)

• Spring Data support

• JAX-WS access to SOA Business layer

Integrations (JAR)

Discovery Design Build QA Deployment Operations

Development

Versioning

Spring I/O

2016

Modification type New

Major

New

Minor

New

Fix

New

Qualifier

No interface modification NO NO YES YES

Interface modification and backwards compatible NO YES YES YES

Interface modification not backwards compatible YES YES YES YES

Pain point: synchronize Maven (pom.xml) and Spring Cloud version (FeignClient)

Manual Automatic

MAJOR.MINOR.FIX-QUALIFIER

Discovery Design Build QA Deployment Operations

Development

Messaging

Spring I/O

2016

HTTP / JSON

Automatic actions in microservices execution:

Pre-execution

Execution

Post-execution

Headers

Body

Messages

HTTP headers

or payload

Functional

message

Header name Message

HEADER.TRACKING_ID Request /

Response

HEADER.* Request

HEADER.STATUS Response

EXCEPTION Response (error)

+ Code

+ Type

+ Severity

+ Description

+ Cause

Discovery Design Build QA Deployment Operations

Development

Integrations

Spring I/O

2016

Discovery Design Build QA Deployment Operations

Development:

1. [MS/SOA] Client JAR (Feign/JAX-WS)

uploaded to Artifactory

2. Consumer adds Maven

dependencies:

• [MS/SOA] Client JAR

• [DB] JDBC driver

3. [DB] Implement Spring Data domain

and repository classes

4. Implement integration logic

• [MS/SOA] @Autowire client

class

• [DB] @Autowire Spring Data

repository

[MS/SOA] Execution:

1. On-the-fly configurations

2. Propagate architecture headers

Client JAR upload

Add Maven dependencies

Data model

Integration logic

Development

Performance enhancements

Spring I/O

2016

Discovery Design Build QA Deployment Operations

HTTP 1.1 caching RFC: https://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html

Spring MVC Cache Control: https://github.com/foo4u/spring-mvc-cache-control

• HTTP 1.1 Caching RFC 2616 compatible with all web browsers

• Cache Control and ETag HTTP header support HTTP cache

• Partial requests: optional input parameters

• Partial responses: query params “fields” and “fieldsExcluded” to filter output messages

Partial resources

• GZip compression in Spring Boot and Feign GZip

compression

Development

Unit & integrated testing

Spring I/O

2016

Discovery Design Build QA Deployment Operations

Continuous Integration

Integrated testing

Unit testing

Testing frameworks

Granularity: for each class

Naming convention: *Test.java

Approach: TDD

Mock: external class

dependencies

Granularity: for each Microservice

Naming convention: *IT.java

Approach: BDD

Mock: Microservice external

systems

Development

Source code quality

Spring I/O

2016

Discovery Design Build QA Deployment Operations

• IDE plugins: Findbugs, Checkstyle, PMD, Code Coverage and SonarQube plugins

Development

• Maven plugins: SonarQube (quality reports), Surefire (unit testing) and Jacoco (Code Coverage)

Build

Spring I/O

2016

DEPLOYMENT

Deployment

Continuous Integration

Spring I/O

2016

Discovery Design Build QA Deployment Operations

Compile Test QA Sonar Analysis

Package Deploy to Artifactory

Deploy to Infrastructure

Deployment

Infrastructure (I)

Spring I/O

2016

Discovery Design Build QA Deployment Operations

• PaaS is the perfect fit for Microservices, providing features that simplify

microservices development and deployment.

Polyglot languages and frameworks

Consistent testing environments

Scaling

Instant Rollback and Versioning

Self Service

Deployment

Infrastructure (and II)

Spring I/O

2016

Discovery Design Build QA Deployment Operations

API Gateway

Routing

Services Runtime

Persistent Volumes

Platform Runtime Administration

Console

CLI/API

PaaS basic model

Continuous

integration

Build

Test

Deploy

Zuul Gateway

Eureka

Registry

Configuration

Monitoring

MicroServices

Configuration

Logs

Spring I/O

2016

OPERATION

Operation

Spring Cloud Dashboard

Spring I/O

2016

Discovery Design Build QA Deployment Operations

• Simple GUI to administrate Spring Cloud applications infrastructure

• Fork of Spring Boot Admin to manage applications registered in service

registry (like Eureka).

Features for every register service

• Show name/id and version number

• Show health status

• Show details, like • Java System / Environment / Spring

properties

• JVM & memory metrics

• Counter & gauge Metrics

• Datasource Metrics

• Easy logger level management

• Interact with JMX-Beans

• View Threaddump

• Application registry history ( from Eureka Server )

• Circuit Breaker dashboard ( from Hystrix or Turbine )

Operation

Logging Discovery Design Build QA Deployment Operations

• Centralized Logging with ELK Stack

Front App

Front App

API Gateway

Business Services - SOA Microservices

Central

Logging

Server ETL Store Dashboards

Logging

MicroService Async call

e2e trackingId

Spring I/O

2016

Operation

Audit Discovery Design Build QA Deployment Operations

Spring I/O

2016

• Audit events integrated in centralized logging system

• Extended to Front and SOA Layer to provide e2e traceability

Start

Request Sent

Response received

End

Error

Functional

Automatically

generated

Generated

from

application

Event types

Event info

Timestamp

Event Type

Hostname

TrackingId

Source Application

Arch version

Error info

App Version

Message

JVMName

MicroServiceType

MicroServiceID

MIcroServiceName

OperationName RequestMapping

Automatically

generated

Generated

from

application/

architecture

Microservice layer specific

Spring I/O

2016

DEMO

Spring I/O

2016

CONCLUSIONS

Conclusions

Final thoughts

Spring I/O

2016

• Microservices architectures have a lot of positive aspects but also challenges to be solved, technical and related to the enterprise.

• Design is a key concept, there’s no silver bullet but some techniques can help.

• Standardised tools and procedures aids productivity and scalability in big projects...

• …but extensible and open for future incremental enhancements.

• PaaS environments are best suited for microservices deployment.

Lessons learned

• Brixton upgrade, Docker, HATEOAS, Event management, Asynchronous messaging, …

Backlog

Spring I/O

2016

QUESTIONS

Spring I/O

2016

everis.com

Consulting, IT & Outsourcing Professional Services