SlideShare a Scribd company logo
1 of 41
Download to read offline
www.faros.be
Migrating a modern spring web
application to serverless
Wim Creuwels
@wimcreuwels
Jeroen Sterken
@jeroensterken
www.faros.be
Cloud Native Enterprise
Development
• Software development / Projects
• IT Consultancy
• Audit/training
Technology focus
• Spring Ecosystem
• Pivotal CloudFoundry
Migrating a modern spring web application to serverless
Serverless
Reactive
Leuven (Belgium)
https://www.meetup.com/Serverless-Belgium
www.faros.be
Migrating a modern spring web application to serverless
Migrating a modern spring web application to serverless
https://freepik.com
Why?
www.faros.be
Migrating a modern spring web application to serverless
Migrating a modern spring web application to serverless
www.faros.be
S e r v e r l e s s a r c h i t e c t u r e s a r e a p p l i c a t i o n d e s i g n s t h a t i n c o r p o r a t e t h i r d - p a r t y
“ B a c k e n d a s a S e r v i c e ” ( B a a S ) s e r v i c e s a n d / o r c u s t o m c o d e r u n i n m a n a g e d ,
e p h e m e r a l c o n t a i n e r s o n a “ F u n c t i o n s a s a S e r v i c e ” ( F a a S ) p l a t f o r m
Migrating a modern spring web application to serverless
M i k e R o b e r t s
www.faros.be
Migrating a modern spring web application to serverless
• Goals
• ‘Traditional’ vs Serverless architecture
• Functionality
• Web / Websockets / Database / Security
• Serverless landscape (tooling / frameworks / platform maturity)
• Best practices (a practice? maturity?)
• Inter-platform compatibility
• Scalable
• Spring support (Cloud Function)
Migrating a modern spring web application to serverless
www.faros.beMigrating a modern spring web application to serverless
You have to let it all go.
Fear, doubt and disbelief.
Free your mind
www.faros.be
Application: Slot Reservation system
Migrating a modern spring web application to serverless
www.faros.be
Application: Slot Reservation system
Migrating a modern spring web application to serverless
www.faros.beMigrating a modern spring web application to serverless
Technical approach
www.faros.be
Server
Technical approach
Migrating a modern spring web application to serverless
O r i g i n a l a r c h i t e c t u r e
MVC/Vaadin
Service
SpringDataJPA
SQL
db
internet
www.faros.be
Server
Technical approach
Migrating a modern spring web application to serverless
S e r v e r l e s s a r c h i t e c t u r e – p a r t 1
Service
SpringDataJPA
SQL
db
MVC/Vaadin
internet
Infrastructure As Code
JSON Server
BaaS
www.faros.be
Technical approach
Migrating a modern spring web application to serverless
Facade Service Data
Interface Impl
deliverydayService.findByDateAndLocation(date, location);
slotService.findSlotsByDateAndLocation(deliveryday);getSlots(Date date, long locationId)
APIGateway
AWSstepfct
AWS Lambda LayerJARJAR JAR
www.faros.be
Technical approach
• Business logic
• Java
• Spring Cloud Function (Abstraction)
• Supportive
• Interpreted language (NodeJS)
• Mix/combine programming languages
Migrating a modern spring web application to serverless
P r o g r a m m i n g L a n g u a g e
www.faros.be
Technical approach
• Public
• AWS Lambda
• Azure Functions
• Google Cloud Functions
• On-Prem / OSS
• PFS
• OpenWhisk
• Fission
• Kubeless
• OpenFaaS
• Oracle fn
• ...
Migrating a modern spring web application to serverless
P l a t f o r m s
www.faros.beMigrating a modern spring web application to serverless
Implementation
BaaS OperationsFaaS
www.faros.be
Implementation
Migrating a modern spring web application to serverless
F u n c t i o n s
event
source
Handler:
function.reservation.get.Handler
Input (json)
Output (json)
www.faros.be
Implementation
• Decouple development from any specific runtime
• Uniform programming model
• Run standalone (locally or in a PaaS)
• Enable Spring Boot features (auto-configuration, DI, metrics)
Migrating a modern spring web application to serverless
S p r i n g C l o u d F u n c t i o n
www.faros.be
Implementation
Migrating a modern spring web application to serverless
S p r i n g C l o u d F u n c t i o n
@Bean
Function f() {
...
}
AWS
Lambda
Apache
OpenWhisk
Azure
Spring
Boot App
REST
f() f() f()
f()
Spring
Boot App
Task
f()
Spring
Boot App
Stream
f()
www.faros.be
Implementation
Migrating a modern spring web application to serverless
S p r i n g C l o u d F u n c t i o n
f
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-aws</artifactId>
</dependency>
• Add mvn dependency
www.faros.be
Implementation
Migrating a modern spring web application to serverless
B u i l d
f
• Jar layout
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>1.0.21.RELEASE</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
www.faros.be
Implementation
Migrating a modern spring web application to serverless
B u i l d
f
• Jar layout
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<finalName>get-reservation</finalName>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</plugin>
</plugins>
www.faros.be
Implementation
• SAM for building serverless applications
• Package functions (ZIP)
Migrating a modern spring web application to serverless
B u i l d
+ set MAIN_CLASS environment variable
www.faros.be
Implementation
Migrating a modern spring web application to serverless
Facade Service Data
Interface Impl
APIGateway
AWSstepfct
AWS Lambda LayerJARJAR JAR
S t e p f u n c t i o n s
www.faros.be
Implementation
• Orchestration
• Statemachine
• Patterns
• Workflow logic
Tasks, choice, pass, fail, (parallel)
• Error handling
• Timeouts/retries
Migrating a modern spring web application to serverless
S t e p f u n c t i o n s
www.faros.be
Implementation
• Testing serverless (microservices) is hard
Migrating a modern spring web application to serverless
T e s t i n g
Test pyramid
https://medium.freecodecamp.org/the-best-ways-to-test-your-serverless-applications-40b88d6ee31e
Serverless Test pyramid
www.faros.be
DEMO
www.faros.beMigrating a modern spring web application to serverless
Implementation
OperationsFaaSBaaS
www.faros.be
BaaS
Migrating a modern spring web application to serverless
A r c h i t e c t u r e
SQL
db
internet
Infrastructure As Code
www.faros.beMigrating a modern spring web application to serverless
Implementation
FaaSBaaS Operations
www.faros.beMigrating a modern spring web application to serverless
www.faros.be
terraform {
backend "s3" {
bucket = “myapp-terraform-state"
key = "tst_serverless_myapp.tfstate"
region = "eu-west-1"
profile = “..."
}
}
provider "aws" {
region = "${var.aws_region}"
profile = "${var.aws_profile}"
}
resource "aws_db_instance" "db_instance" {
name = “myapp-db"
engine = "postgres"
engine_version = "10.6“
...
}
Operations
• Terraform (HashiCorp)
• Open source
• Multi-platform support
• Independant state
• Integration
• Missing API Gateway websocket
Migrating a modern spring web application to serverless
I n f r a s t r u c t u r e A s C o d e
www.faros.be
Operations
• SAM (building serverless applications)
• SAM template (uses Cloudformation)
• Local Testing and Debugging
• Build automation
• Built-in best practices (ex. gradual deployments)
Migrating a modern spring web application to serverless
A W S S A M
www.faros.be
Operations
Migrating a modern spring web application to serverless
I n f r a s t r u c t u r e A s C o d e
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
GetReservationsFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: function/get-reservations
Handler: function.reservation.get.Handler
Runtime: java8
Events:
GetReservations:
Type: Api
Properties:
RestApiId: !Ref ReservationsApi
Path: /reservations
Method: get
....
SAM Translator
AWSTemplateFormatVersion: '2010-09-09'
Resources:
....
Cloudformation
templateSAM template
www.faros.beMigrating a modern spring web application to serverless
#1 REST API
#1 WS API
#2 db
#1 AWS Step Function
AWS Secrets Manager
#10 AWS access roles
#7 fct
#1 Template!
www.faros.be
Operations
• CI/CD
• AWS CodeBuild / AWS CodeDeploy / AWS CodePipeline
• Monitoring
• CloudWatch
• AWS X-Ray
Migrating a modern spring web application to serverless
O t h e r
www.faros.be
DEMO
www.faros.be
Conclusions
• Still quite new
• Little guidance / expertise / resources
• Trial & error
• Focus on 1 platform
• Distributed systems/patterns!
• Idempotent, stateless, transactions, ...
• Serverless != #NoOps
• Code
• Organize functions is important
• Java might not be your default language choice
• Mix/combine programming languages based on needs
Migrating a modern spring web application to serverless
www.faros.be
Conclusions
• No walk in the park
• Limited resources (doc)
• Little experience
• Operations (deploy with versioning, ...)
• Linking of small functions
• Design patterns (event-driven, SRP)
• Reusability
• State machine
Migrating a modern spring web application to serverless
www.faros.be
Thanks!
Q&A
Wim Creuwels
@wimcreuwels
Jeroen Sterken
@jeroensterken
www.faros.be
Contact
Gaston Geenslaan 11 B4
3000 Leuven
hello@faros.be
+32(0)16 240 840
Migrating a modern spring web application to serverless
@FarosBelgium farosbe

More Related Content

What's hot

Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Amazon Web Services
 

What's hot (20)

Lessons Learned from building a serverless API
Lessons Learned from building  a serverless APILessons Learned from building  a serverless API
Lessons Learned from building a serverless API
 
Serverless Apps with AWS Step Functions
Serverless Apps with AWS Step FunctionsServerless Apps with AWS Step Functions
Serverless Apps with AWS Step Functions
 
Building your own calendly using amazon app sync
Building your own calendly using amazon app syncBuilding your own calendly using amazon app sync
Building your own calendly using amazon app sync
 
Building a Serverless Pipeline
Building a Serverless PipelineBuilding a Serverless Pipeline
Building a Serverless Pipeline
 
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
Building CICD Pipelines for Serverless Applications - DevDay Austin 2017
 
Building Serverless Web Applications
Building Serverless Web Applications Building Serverless Web Applications
Building Serverless Web Applications
 
Choosing the right messaging service for your serverless app [with lumigo]
Choosing the right messaging service for your serverless app [with lumigo]Choosing the right messaging service for your serverless app [with lumigo]
Choosing the right messaging service for your serverless app [with lumigo]
 
The Rise of Serverless Architectures
The Rise of Serverless ArchitecturesThe Rise of Serverless Architectures
The Rise of Serverless Architectures
 
Serverless Development Deep Dive
Serverless Development Deep DiveServerless Development Deep Dive
Serverless Development Deep Dive
 
Serverless
ServerlessServerless
Serverless
 
Building Advanced Serverless Applications
Building Advanced Serverless ApplicationsBuilding Advanced Serverless Applications
Building Advanced Serverless Applications
 
Artificial Intelligence & Machine learning foundation topic in AWS
Artificial Intelligence & Machine learning foundation topic in AWS Artificial Intelligence & Machine learning foundation topic in AWS
Artificial Intelligence & Machine learning foundation topic in AWS
 
Building Serverless Web Applications - May 2017 AWS Online Tech Talks
Building Serverless Web Applications  - May 2017 AWS Online Tech TalksBuilding Serverless Web Applications  - May 2017 AWS Online Tech Talks
Building Serverless Web Applications - May 2017 AWS Online Tech Talks
 
Workshop : Wild Rydes Takes Off - The Dawn of a New Unicorn
Workshop : Wild Rydes Takes Off - The Dawn of a New UnicornWorkshop : Wild Rydes Takes Off - The Dawn of a New Unicorn
Workshop : Wild Rydes Takes Off - The Dawn of a New Unicorn
 
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
 
ESPC Webinar - From SharePoint to Office 365 Development
ESPC Webinar - From SharePoint to Office 365 DevelopmentESPC Webinar - From SharePoint to Office 365 Development
ESPC Webinar - From SharePoint to Office 365 Development
 
Riga Dev Days: Building a Smart Security Camera with Raspberry Pi Zero, Node....
Riga Dev Days: Building a Smart Security Camera with Raspberry Pi Zero, Node....Riga Dev Days: Building a Smart Security Camera with Raspberry Pi Zero, Node....
Riga Dev Days: Building a Smart Security Camera with Raspberry Pi Zero, Node....
 
SharePoint Fest DC 2018 - From SharePoint to Office 365 Development
SharePoint Fest DC 2018 - From SharePoint to Office 365 DevelopmentSharePoint Fest DC 2018 - From SharePoint to Office 365 Development
SharePoint Fest DC 2018 - From SharePoint to Office 365 Development
 
Sloppy Little Serverless Stories
Sloppy Little Serverless StoriesSloppy Little Serverless Stories
Sloppy Little Serverless Stories
 
SharePoint Saturday Calgary 2017 - From SharePoint to Office 365 Development
SharePoint Saturday Calgary 2017 - From SharePoint to Office 365 DevelopmentSharePoint Saturday Calgary 2017 - From SharePoint to Office 365 Development
SharePoint Saturday Calgary 2017 - From SharePoint to Office 365 Development
 

Similar to Migrating a modern spring web application to serverless

Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon Web Services
 

Similar to Migrating a modern spring web application to serverless (20)

Handling Asynchronous Workloads With OpenShift and Iron.io
Handling Asynchronous Workloads With OpenShift and Iron.ioHandling Asynchronous Workloads With OpenShift and Iron.io
Handling Asynchronous Workloads With OpenShift and Iron.io
 
Microservices Architecture for Web Applications using AWS Lambda and more
Microservices Architecture for Web Applications using AWS Lambda and moreMicroservices Architecture for Web Applications using AWS Lambda and more
Microservices Architecture for Web Applications using AWS Lambda and more
 
Microservices Architecture for Web Applications using Serverless Computing wi...
Microservices Architecture for Web Applications using Serverless Computing wi...Microservices Architecture for Web Applications using Serverless Computing wi...
Microservices Architecture for Web Applications using Serverless Computing wi...
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Azure Functions Real World Examples
Azure Functions Real World Examples Azure Functions Real World Examples
Azure Functions Real World Examples
 
Microservices Architecture for MEAN Applications using Serverless AWS
Microservices Architecture for MEAN Applications using Serverless AWSMicroservices Architecture for MEAN Applications using Serverless AWS
Microservices Architecture for MEAN Applications using Serverless AWS
 
Microservices Architecture for Web Applications using Amazon AWS Cloud
Microservices Architecture for Web Applications using Amazon AWS CloudMicroservices Architecture for Web Applications using Amazon AWS Cloud
Microservices Architecture for Web Applications using Amazon AWS Cloud
 
Build Web Applications using Microservices on Node.js and Serverless AWS
Build Web Applications using Microservices on Node.js and Serverless AWSBuild Web Applications using Microservices on Node.js and Serverless AWS
Build Web Applications using Microservices on Node.js and Serverless AWS
 
AWS Summit Berlin 2013 - Next-Generation Websites on Demand – with Infopark C...
AWS Summit Berlin 2013 - Next-Generation Websites on Demand – with Infopark C...AWS Summit Berlin 2013 - Next-Generation Websites on Demand – with Infopark C...
AWS Summit Berlin 2013 - Next-Generation Websites on Demand – with Infopark C...
 
Microservices Architecture for Digital Platforms using Serverless AWS
Microservices Architecture for Digital Platforms using Serverless AWSMicroservices Architecture for Digital Platforms using Serverless AWS
Microservices Architecture for Digital Platforms using Serverless AWS
 
ARC201 Microservices Architecture @ AWS re:Invent 2015
ARC201 Microservices Architecture @ AWS re:Invent 2015ARC201 Microservices Architecture @ AWS re:Invent 2015
ARC201 Microservices Architecture @ AWS re:Invent 2015
 
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
 
Real World SharePoint Framework and Azure Services
Real World SharePoint Framework and Azure ServicesReal World SharePoint Framework and Azure Services
Real World SharePoint Framework and Azure Services
 
Building compelling Enterprise Solutions on AWS
Building compelling Enterprise Solutions on AWSBuilding compelling Enterprise Solutions on AWS
Building compelling Enterprise Solutions on AWS
 
NodeJS Interactive 2019: FaaS meets Frameworks
NodeJS Interactive 2019:  FaaS meets FrameworksNodeJS Interactive 2019:  FaaS meets Frameworks
NodeJS Interactive 2019: FaaS meets Frameworks
 
Application Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless WorldApplication Lifecycle Management in a Serverless World
Application Lifecycle Management in a Serverless World
 
Azure Cloud Application Development Workshop - UGIdotNET
Azure Cloud Application Development Workshop - UGIdotNETAzure Cloud Application Development Workshop - UGIdotNET
Azure Cloud Application Development Workshop - UGIdotNET
 
Measure and Increase Developer Productivity with Help of Serverless at AWS Co...
Measure and Increase Developer Productivity with Help of Serverless at AWS Co...Measure and Increase Developer Productivity with Help of Serverless at AWS Co...
Measure and Increase Developer Productivity with Help of Serverless at AWS Co...
 
Azure Serverless Toolbox
Azure Serverless ToolboxAzure Serverless Toolbox
Azure Serverless Toolbox
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Migrating a modern spring web application to serverless

  • 1. www.faros.be Migrating a modern spring web application to serverless Wim Creuwels @wimcreuwels Jeroen Sterken @jeroensterken
  • 2. www.faros.be Cloud Native Enterprise Development • Software development / Projects • IT Consultancy • Audit/training Technology focus • Spring Ecosystem • Pivotal CloudFoundry Migrating a modern spring web application to serverless Serverless Reactive Leuven (Belgium) https://www.meetup.com/Serverless-Belgium
  • 3. www.faros.be Migrating a modern spring web application to serverless Migrating a modern spring web application to serverless https://freepik.com Why?
  • 4. www.faros.be Migrating a modern spring web application to serverless Migrating a modern spring web application to serverless
  • 5. www.faros.be S e r v e r l e s s a r c h i t e c t u r e s a r e a p p l i c a t i o n d e s i g n s t h a t i n c o r p o r a t e t h i r d - p a r t y “ B a c k e n d a s a S e r v i c e ” ( B a a S ) s e r v i c e s a n d / o r c u s t o m c o d e r u n i n m a n a g e d , e p h e m e r a l c o n t a i n e r s o n a “ F u n c t i o n s a s a S e r v i c e ” ( F a a S ) p l a t f o r m Migrating a modern spring web application to serverless M i k e R o b e r t s
  • 6. www.faros.be Migrating a modern spring web application to serverless • Goals • ‘Traditional’ vs Serverless architecture • Functionality • Web / Websockets / Database / Security • Serverless landscape (tooling / frameworks / platform maturity) • Best practices (a practice? maturity?) • Inter-platform compatibility • Scalable • Spring support (Cloud Function) Migrating a modern spring web application to serverless
  • 7. www.faros.beMigrating a modern spring web application to serverless You have to let it all go. Fear, doubt and disbelief. Free your mind
  • 8. www.faros.be Application: Slot Reservation system Migrating a modern spring web application to serverless
  • 9. www.faros.be Application: Slot Reservation system Migrating a modern spring web application to serverless
  • 10. www.faros.beMigrating a modern spring web application to serverless Technical approach
  • 11. www.faros.be Server Technical approach Migrating a modern spring web application to serverless O r i g i n a l a r c h i t e c t u r e MVC/Vaadin Service SpringDataJPA SQL db internet
  • 12. www.faros.be Server Technical approach Migrating a modern spring web application to serverless S e r v e r l e s s a r c h i t e c t u r e – p a r t 1 Service SpringDataJPA SQL db MVC/Vaadin internet Infrastructure As Code JSON Server BaaS
  • 13. www.faros.be Technical approach Migrating a modern spring web application to serverless Facade Service Data Interface Impl deliverydayService.findByDateAndLocation(date, location); slotService.findSlotsByDateAndLocation(deliveryday);getSlots(Date date, long locationId) APIGateway AWSstepfct AWS Lambda LayerJARJAR JAR
  • 14. www.faros.be Technical approach • Business logic • Java • Spring Cloud Function (Abstraction) • Supportive • Interpreted language (NodeJS) • Mix/combine programming languages Migrating a modern spring web application to serverless P r o g r a m m i n g L a n g u a g e
  • 15. www.faros.be Technical approach • Public • AWS Lambda • Azure Functions • Google Cloud Functions • On-Prem / OSS • PFS • OpenWhisk • Fission • Kubeless • OpenFaaS • Oracle fn • ... Migrating a modern spring web application to serverless P l a t f o r m s
  • 16. www.faros.beMigrating a modern spring web application to serverless Implementation BaaS OperationsFaaS
  • 17. www.faros.be Implementation Migrating a modern spring web application to serverless F u n c t i o n s event source Handler: function.reservation.get.Handler Input (json) Output (json)
  • 18. www.faros.be Implementation • Decouple development from any specific runtime • Uniform programming model • Run standalone (locally or in a PaaS) • Enable Spring Boot features (auto-configuration, DI, metrics) Migrating a modern spring web application to serverless S p r i n g C l o u d F u n c t i o n
  • 19. www.faros.be Implementation Migrating a modern spring web application to serverless S p r i n g C l o u d F u n c t i o n @Bean Function f() { ... } AWS Lambda Apache OpenWhisk Azure Spring Boot App REST f() f() f() f() Spring Boot App Task f() Spring Boot App Stream f()
  • 20. www.faros.be Implementation Migrating a modern spring web application to serverless S p r i n g C l o u d F u n c t i o n f <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-function-context</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-function-adapter-aws</artifactId> </dependency> • Add mvn dependency
  • 21. www.faros.be Implementation Migrating a modern spring web application to serverless B u i l d f • Jar layout <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <dependencies> <dependency> <groupId>org.springframework.boot.experimental</groupId> <artifactId>spring-boot-thin-layout</artifactId> <version>1.0.21.RELEASE</version> </dependency> </dependencies> </plugin> ... </plugins>
  • 22. www.faros.be Implementation Migrating a modern spring web application to serverless B u i l d f • Jar layout <plugins> ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <configuration> <finalName>get-reservation</finalName> <createDependencyReducedPom>false</createDependencyReducedPom> </configuration> </plugin> </plugins>
  • 23. www.faros.be Implementation • SAM for building serverless applications • Package functions (ZIP) Migrating a modern spring web application to serverless B u i l d + set MAIN_CLASS environment variable
  • 24. www.faros.be Implementation Migrating a modern spring web application to serverless Facade Service Data Interface Impl APIGateway AWSstepfct AWS Lambda LayerJARJAR JAR S t e p f u n c t i o n s
  • 25. www.faros.be Implementation • Orchestration • Statemachine • Patterns • Workflow logic Tasks, choice, pass, fail, (parallel) • Error handling • Timeouts/retries Migrating a modern spring web application to serverless S t e p f u n c t i o n s
  • 26. www.faros.be Implementation • Testing serverless (microservices) is hard Migrating a modern spring web application to serverless T e s t i n g Test pyramid https://medium.freecodecamp.org/the-best-ways-to-test-your-serverless-applications-40b88d6ee31e Serverless Test pyramid
  • 28. www.faros.beMigrating a modern spring web application to serverless Implementation OperationsFaaSBaaS
  • 29. www.faros.be BaaS Migrating a modern spring web application to serverless A r c h i t e c t u r e SQL db internet Infrastructure As Code
  • 30. www.faros.beMigrating a modern spring web application to serverless Implementation FaaSBaaS Operations
  • 31. www.faros.beMigrating a modern spring web application to serverless
  • 32. www.faros.be terraform { backend "s3" { bucket = “myapp-terraform-state" key = "tst_serverless_myapp.tfstate" region = "eu-west-1" profile = “..." } } provider "aws" { region = "${var.aws_region}" profile = "${var.aws_profile}" } resource "aws_db_instance" "db_instance" { name = “myapp-db" engine = "postgres" engine_version = "10.6“ ... } Operations • Terraform (HashiCorp) • Open source • Multi-platform support • Independant state • Integration • Missing API Gateway websocket Migrating a modern spring web application to serverless I n f r a s t r u c t u r e A s C o d e
  • 33. www.faros.be Operations • SAM (building serverless applications) • SAM template (uses Cloudformation) • Local Testing and Debugging • Build automation • Built-in best practices (ex. gradual deployments) Migrating a modern spring web application to serverless A W S S A M
  • 34. www.faros.be Operations Migrating a modern spring web application to serverless I n f r a s t r u c t u r e A s C o d e AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: GetReservationsFunction: Type: AWS::Serverless::Function Properties: CodeUri: function/get-reservations Handler: function.reservation.get.Handler Runtime: java8 Events: GetReservations: Type: Api Properties: RestApiId: !Ref ReservationsApi Path: /reservations Method: get .... SAM Translator AWSTemplateFormatVersion: '2010-09-09' Resources: .... Cloudformation templateSAM template
  • 35. www.faros.beMigrating a modern spring web application to serverless #1 REST API #1 WS API #2 db #1 AWS Step Function AWS Secrets Manager #10 AWS access roles #7 fct #1 Template!
  • 36. www.faros.be Operations • CI/CD • AWS CodeBuild / AWS CodeDeploy / AWS CodePipeline • Monitoring • CloudWatch • AWS X-Ray Migrating a modern spring web application to serverless O t h e r
  • 38. www.faros.be Conclusions • Still quite new • Little guidance / expertise / resources • Trial & error • Focus on 1 platform • Distributed systems/patterns! • Idempotent, stateless, transactions, ... • Serverless != #NoOps • Code • Organize functions is important • Java might not be your default language choice • Mix/combine programming languages based on needs Migrating a modern spring web application to serverless
  • 39. www.faros.be Conclusions • No walk in the park • Limited resources (doc) • Little experience • Operations (deploy with versioning, ...) • Linking of small functions • Design patterns (event-driven, SRP) • Reusability • State machine Migrating a modern spring web application to serverless
  • 41. www.faros.be Contact Gaston Geenslaan 11 B4 3000 Leuven hello@faros.be +32(0)16 240 840 Migrating a modern spring web application to serverless @FarosBelgium farosbe