SlideShare a Scribd company logo
Serverless in Java
Lessons learnt
Krzysztof Pawlowski
krzysztof.pawlowski@merapar.com
JEE Conf, 27.04.2019 Kyiv
About me
• Helping clients create value with innovative cloud
solutions @ Merapar
• Teaching students good programming practices @ Polish-
Japanese Academy of IT
• 10+ years of experience with Java
• 2 years of experience with AWS
• Certified AWS Solutions Architect and AWS Developer
Agenda
• What is serverless?
• Why did we choose serverless and Java?
• What did we learn when using Java for serverless solution?
• Best practices

–Techopedia
“Serverless computing is a type of cloud computing
where the customer does not have to provision
servers for the back-end code to run on, but (…)
cloud provider starts and stops a container
platform as a service as requests come (…).”
How does serverless work?
Function A
Function A
code / jars storage
Serverless Computing Platform
Execution
Environment
Server
Execution
Environment
Server
Execution
Environment
Server
Execution
Environment
Server
Client
Function A
1. Execute Function A
2. Retrieve Function A
5. Return result
3. Deploy Function A 4. Run Function A
How does serverless work?
EC2 instance (server)
Execution environment
JVM
Request Handler
Our use-case: migration project
• Migration of several million users and devices to a new platform
• Users decide when they want to migrate
• Users and data are migrated to a new backoffice
• Firmware is upgraded
• How to orchestrate the migration process?

Our use-case: migration project
Why serverless?
• No servers to manage
• Simplified deployment and packaging (AWS Cloudformation)
• Automatic continuous scaling
• No idle / cold servers = no costs when not used
• Pay per request
• Availability and fault tolerance build in 

Why Java?
• Competencies in a team
• Well tested libraries
• Strongly typed language
• AWS SDK for Java
• Tooling: IntelliJ IDEA, Maven etc.
Lesson 1: What
should be the project
structure?
Project structure
or
One big Maven project Maven project per AWS Lambda
Project structure


One big maven project



Pros:
• easier building process
• code re-usage

Cons:
• longer time needed to 

download/unpack package 

before invocation


Maven project per lambda
Pros:
• single functionality deployment
• lambda code separation / loose
coupling
• shorter time needed to download/
unpack package before invocation
Cons:
• code duplication
Lesson 2: Where has
the complexity
moved to?
Endpoint definition in Spring Boot
  @RequestMapping(method = RequestMethod.POST)

@ResponseStatus(HttpStatus.CREATED)

@ResponseBody

@Path(“/foo”)

public Long create(@RequestBody Foo resource) {

      return service.create(resource);

  }
Endpoint definition in AWS
AWS IAM
AWS API Gateway AWS Lambda
• complexity moved from
one codebase to multiple
services
• initial bootstrapping is
more work

Endpoint definition in AWS
1. implement AWS Lambda handler
import com.amazonaws.services.lambda.runtime.Context
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class Hello implements RequestHandler<Foo, Long> {

public Long myHandler(Foo resource, Context context) {

return service.create(resource);

}

}
Endpoint definition in AWS
2. create API Gateway endpoint definition
• a long json definition including:
• OpenAPI definition (aka Swagger) of the endpoint
• all responses mappings
• all errors mappings
Endpoint definition in AWS
3. create IAM role for API Gateway to call AWS Lambda
"LambdaPermission": {

"Type": "AWS::Lambda::Permission",

"Properties": {

"Action": "lambda:invokeFunction",

"FunctionName": “arn:aws:lambda:<region>

:<account-id>:function:hello”,

"Principal": "apigateway.amazonaws.com",

“SourceArn”:”arn:aws:execute-api:<region>

:<account_id>:HelloApi"

}

}
Developer now needs to
know more about
infrastructure/platform
Lesson 3: How to
debug/troubleshoot?
Debugging
image: https://www.jetbrains.com/help/idea/migrating-from-eclipse-to-intellij-idea.html
?
No remote debugging
Running your code locally
• AWS SAM (Serverless Application
Model) Local
• simulates AWS cloud on your
machine
• Eclipse/IntelliJ plugin - possible
to debug locally
• not all the services are
implemented
IntelliJ AWS toolkit
source: https://aws.amazon.com/blogs/developer/aws-toolkit-for-intellij-now-generally-available/
IntelliJ AWS toolkit
source: https://aws.amazon.com/blogs/developer/aws-toolkit-for-intellij-now-generally-available/
IntelliJ AWS toolkit
source: https://aws.amazon.com/blogs/developer/aws-toolkit-for-intellij-now-generally-available/
Metrics and logs
• Metrics and monitoring
• CloudWatch
• X-Ray
Metrics and logs
• Logs
• CloudWatch

Logs Insights
• ElasticSearch /
Kibana
• All managed by AWS
Lesson 4: What is
the performance?
Java performance in AWS
• AWS Lambda performance test based simple application exposing GET
endpoint returning “Hello world” response written in:
• Java
• Node.JS
• C# (.net core sdk 2.0)
• F#
• Go
• Python
• Run in with 1024MB MEM
• Cold start not taken into account
Java performance in AWS
Java code had average performance
Java performance in AWS
Java code had consistent performance
Java performance in AWS
Java endpoint had similar performance to other languages
Java performance in AWS
Java endpoint had a consistent performance
Performance tuning
AWS Lambda
• you pay per 100 ms
• price depends on amount of memory
• cpu depends on amount of memory
Performance tuning
Performance tuning
Lesson 5: Cold start
might be an issue
Cold start
Downloading the
code
Starting the
execution
environment
Bootstrapping the
runtime
Running the code
AWS optimisation User optimisation
Cold start
Total execution time
Warm start
Cold start
1st call
Cold start
Running
the code
Running
the code
Running
the code
Running
the code
2nd call 3rd call 4th call
First execution of lambda function
Cold start
Cold start
Running
the code
Cold start
Running
the code
> 20..45mins
Big interval between lambdas invocation
Cold start
Cold start
Running
the code
Running
the code
Running
the code
Running
the code
Cold start
Running
the code
Running
the code
Cold start
Running
the code
Running
the code
Running
the code
Concurrent lambda invocations (can be limited in lambda definition)
- new execution environment created
Cold start
• In case of Java cold start might take couple of seconds
• Less harmful in dynamically typed languages (Python, Node.JS)
• Bigger jar file increases cold start
Decreasing cold start time
• Increase memory/cpu for lambda function
• might increase the cost
• Separate jar file for each lambda function
• Go for dynamically typed language
Eliminating cold start time
• Pre-warm lambda
• call lambda every ~20 min to keep it warm (cronjob)
• cost assuming 3GB mem lambda running for 1s every 20 min is
about $1 per year
• for n concurrent lambda executions - run at once n concurrent
lambdas with the same interval
Cold start
• Other option how to handle cold start:
• do nothing!
• it might not be an issue in your case
Lesson 6:
Understand and use
AWS best practices
–Best Practices for Working with AWS Lambda Functions
(https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html)
“Take advantage of Execution Context reuse to
improve the performance of your function.”
Reusing execution context
• Execution context is created during bootstrapping the
environment (part of cold start)
• use static initialisation/constructor, global/static variables and
singletons
• reuse connections: database, http, etc.
• do not create long-initialised objects in the handleRequest
method
–Best Practices for Working with AWS Lambda Functions
(https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html)
“Use AWS Lambda Environment Variables to pass
operational parameters to your function.”
AWS Lambda Environment Variables
–Best Practices for Working with AWS Lambda Functions
(https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html)
“Be familiar with AWS Lambda Limits.”
AWS Lambda limits
• Concurrent executions: 1000
• Function timeout: 900 seconds
• Function memory allocation: 128MB to 3008 MB
• Function environment variables: 4KB
• /tmp directory storage: 512MB
Conclusion
• Is Java good for serverless?
• Definitely yes!
• Is Java always good for serverless?
• Definitely not!
Conclusion
• When to use serverless?
• Unpredictable load of your app
• Low load of the app -> low cost
• No long running processes
• When to use Java in serverless?
• Cold start is not an issue
• Java is a language of preference for the team
Thank you!

Q & A
Krzysztof Pawlowski
krzychpawlowski
krzysztof.pawlowski@merapar.com

More Related Content

What's hot

Adopting Java for the Serverless world at JUG Hamburg
Adopting Java for the Serverless world at  JUG HamburgAdopting Java for the Serverless world at  JUG Hamburg
Adopting Java for the Serverless world at JUG Hamburg
Vadym Kazulkin
 
Open stack ocata summit enabling aws lambda-like functionality with openstac...
Open stack ocata summit  enabling aws lambda-like functionality with openstac...Open stack ocata summit  enabling aws lambda-like functionality with openstac...
Open stack ocata summit enabling aws lambda-like functionality with openstac...
Shaun Murakami
 
New AWS Services
New AWS ServicesNew AWS Services
New AWS Services
Josh Padnick
 
Getting Started with Docker on AWS
Getting Started with Docker on AWSGetting Started with Docker on AWS
Getting Started with Docker on AWS
Amazon Web Services
 
AWS Lambda from the trenches (Serverless London)
AWS Lambda from the trenches (Serverless London)AWS Lambda from the trenches (Serverless London)
AWS Lambda from the trenches (Serverless London)
Yan Cui
 
AWS Lambda Deep Dive
AWS Lambda Deep DiveAWS Lambda Deep Dive
AWS Lambda Deep Dive
Alfonso Cabrera
 
Scala, ECS, Docker: Delayed Execution @Coursera
Scala, ECS, Docker: Delayed Execution @CourseraScala, ECS, Docker: Delayed Execution @Coursera
Scala, ECS, Docker: Delayed Execution @Coursera
C4Media
 
Play Framework + Docker + CircleCI + AWS + EC2 Container Service
Play Framework + Docker + CircleCI + AWS + EC2 Container ServicePlay Framework + Docker + CircleCI + AWS + EC2 Container Service
Play Framework + Docker + CircleCI + AWS + EC2 Container Service
Josh Padnick
 
Continuous Integration and Deployment Best Practices on AWS
Continuous Integration and Deployment Best Practices on AWSContinuous Integration and Deployment Best Practices on AWS
Continuous Integration and Deployment Best Practices on AWS
Danilo Poccia
 
Introduction to Docker on AWS
Introduction to Docker on AWSIntroduction to Docker on AWS
Introduction to Docker on AWS
Amazon Web Services
 
Docker and java
Docker and javaDocker and java
Docker and java
Anthony Dahanne
 
Adopting Java for the Serverless world at JUG London
Adopting Java for the Serverless world at  JUG LondonAdopting Java for the Serverless world at  JUG London
Adopting Java for the Serverless world at JUG London
Vadym Kazulkin
 
Adopting Java for the Serverless world at IT Tage
Adopting Java for the Serverless world at IT TageAdopting Java for the Serverless world at IT Tage
Adopting Java for the Serverless world at IT Tage
Vadym Kazulkin
 
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Amazon Web Services
 
Adapting Java for the Serverless World at JUG Barcelona
Adapting Java for the Serverless World at JUG BarcelonaAdapting Java for the Serverless World at JUG Barcelona
Adapting Java for the Serverless World at JUG Barcelona
Vadym Kazulkin
 
Containerize all the things!
Containerize all the things!Containerize all the things!
Containerize all the things!
Mike Melusky
 
(APP309) Running and Monitoring Docker Containers at Scale | AWS re:Invent 2014
(APP309) Running and Monitoring Docker Containers at Scale | AWS re:Invent 2014(APP309) Running and Monitoring Docker Containers at Scale | AWS re:Invent 2014
(APP309) Running and Monitoring Docker Containers at Scale | AWS re:Invent 2014
Amazon Web Services
 
Continuous Delivery to Amazon EC2 Container Service
Continuous Delivery to Amazon EC2 Container ServiceContinuous Delivery to Amazon EC2 Container Service
Continuous Delivery to Amazon EC2 Container Service
Amazon Web Services
 
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
Amazon Web Services
 
Getting Started with Docker On AWS
Getting Started with Docker On AWSGetting Started with Docker On AWS
Getting Started with Docker On AWS
Amazon Web Services
 

What's hot (20)

Adopting Java for the Serverless world at JUG Hamburg
Adopting Java for the Serverless world at  JUG HamburgAdopting Java for the Serverless world at  JUG Hamburg
Adopting Java for the Serverless world at JUG Hamburg
 
Open stack ocata summit enabling aws lambda-like functionality with openstac...
Open stack ocata summit  enabling aws lambda-like functionality with openstac...Open stack ocata summit  enabling aws lambda-like functionality with openstac...
Open stack ocata summit enabling aws lambda-like functionality with openstac...
 
New AWS Services
New AWS ServicesNew AWS Services
New AWS Services
 
Getting Started with Docker on AWS
Getting Started with Docker on AWSGetting Started with Docker on AWS
Getting Started with Docker on AWS
 
AWS Lambda from the trenches (Serverless London)
AWS Lambda from the trenches (Serverless London)AWS Lambda from the trenches (Serverless London)
AWS Lambda from the trenches (Serverless London)
 
AWS Lambda Deep Dive
AWS Lambda Deep DiveAWS Lambda Deep Dive
AWS Lambda Deep Dive
 
Scala, ECS, Docker: Delayed Execution @Coursera
Scala, ECS, Docker: Delayed Execution @CourseraScala, ECS, Docker: Delayed Execution @Coursera
Scala, ECS, Docker: Delayed Execution @Coursera
 
Play Framework + Docker + CircleCI + AWS + EC2 Container Service
Play Framework + Docker + CircleCI + AWS + EC2 Container ServicePlay Framework + Docker + CircleCI + AWS + EC2 Container Service
Play Framework + Docker + CircleCI + AWS + EC2 Container Service
 
Continuous Integration and Deployment Best Practices on AWS
Continuous Integration and Deployment Best Practices on AWSContinuous Integration and Deployment Best Practices on AWS
Continuous Integration and Deployment Best Practices on AWS
 
Introduction to Docker on AWS
Introduction to Docker on AWSIntroduction to Docker on AWS
Introduction to Docker on AWS
 
Docker and java
Docker and javaDocker and java
Docker and java
 
Adopting Java for the Serverless world at JUG London
Adopting Java for the Serverless world at  JUG LondonAdopting Java for the Serverless world at  JUG London
Adopting Java for the Serverless world at JUG London
 
Adopting Java for the Serverless world at IT Tage
Adopting Java for the Serverless world at IT TageAdopting Java for the Serverless world at IT Tage
Adopting Java for the Serverless world at IT Tage
 
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
 
Adapting Java for the Serverless World at JUG Barcelona
Adapting Java for the Serverless World at JUG BarcelonaAdapting Java for the Serverless World at JUG Barcelona
Adapting Java for the Serverless World at JUG Barcelona
 
Containerize all the things!
Containerize all the things!Containerize all the things!
Containerize all the things!
 
(APP309) Running and Monitoring Docker Containers at Scale | AWS re:Invent 2014
(APP309) Running and Monitoring Docker Containers at Scale | AWS re:Invent 2014(APP309) Running and Monitoring Docker Containers at Scale | AWS re:Invent 2014
(APP309) Running and Monitoring Docker Containers at Scale | AWS re:Invent 2014
 
Continuous Delivery to Amazon EC2 Container Service
Continuous Delivery to Amazon EC2 Container ServiceContinuous Delivery to Amazon EC2 Container Service
Continuous Delivery to Amazon EC2 Container Service
 
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
 
Getting Started with Docker On AWS
Getting Started with Docker On AWSGetting Started with Docker On AWS
Getting Started with Docker On AWS
 

Similar to Serverless in java Lessons learnt

Adopting Java for the Serverless world at Serverless Meetup Singapore
Adopting Java for the Serverless world at Serverless Meetup SingaporeAdopting Java for the Serverless world at Serverless Meetup Singapore
Adopting Java for the Serverless world at Serverless Meetup Singapore
Vadym Kazulkin
 
Adopting Java for the Serverless world at AWS User Group Pretoria
Adopting Java for the Serverless world at AWS User Group PretoriaAdopting Java for the Serverless world at AWS User Group Pretoria
Adopting Java for the Serverless world at AWS User Group Pretoria
Vadym Kazulkin
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
Ryan Cuprak
 
NEW LAUNCH! Developing Serverless C# Applications
NEW LAUNCH! Developing Serverless C# ApplicationsNEW LAUNCH! Developing Serverless C# Applications
NEW LAUNCH! Developing Serverless C# Applications
Amazon Web Services
 
Deep Dive on AWS Lambda - January 2017 AWS Online Tech Talks
Deep Dive on AWS Lambda - January 2017 AWS Online Tech TalksDeep Dive on AWS Lambda - January 2017 AWS Online Tech Talks
Deep Dive on AWS Lambda - January 2017 AWS Online Tech Talks
Amazon Web Services
 
Serverless Computing
Serverless ComputingServerless Computing
Serverless Computing
Anand Gupta
 
Journey towards serverless infrastructure
Journey towards serverless infrastructureJourney towards serverless infrastructure
Journey towards serverless infrastructure
Ville Seppänen
 
JDD2022: How to avoid common mistakes and misconceptions when working with Ja...
JDD2022: How to avoid common mistakes and misconceptions when working with Ja...JDD2022: How to avoid common mistakes and misconceptions when working with Ja...
JDD2022: How to avoid common mistakes and misconceptions when working with Ja...
adebski
 
A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)
Julien SIMON
 
2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)
Enis Afgan
 
Serverless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloadsServerless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloads
Tensult
 
AWS Lambda in C#
AWS Lambda in C#AWS Lambda in C#
AWS Lambda in C#
Amazon Web Services
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
Ganesh Kondal
 
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
Derek Ashmore
 
Deep Dive on AWS Lambda
Deep Dive on AWS LambdaDeep Dive on AWS Lambda
Deep Dive on AWS Lambda
Amazon Web Services
 
Stephen Liedig: Building Serverless Backends with AWS Lambda and API Gateway
Stephen Liedig: Building Serverless Backends with AWS Lambda and API GatewayStephen Liedig: Building Serverless Backends with AWS Lambda and API Gateway
Stephen Liedig: Building Serverless Backends with AWS Lambda and API Gateway
Steve Androulakis
 
Building serverless backends - Tech talk 5 May 2017
Building serverless backends - Tech talk 5 May 2017Building serverless backends - Tech talk 5 May 2017
Building serverless backends - Tech talk 5 May 2017
ARDC
 
Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]
Ryan Cuprak
 
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
Amazon Web Services
 
Geecon2022: How to avoid common mistakes and misconceptions when working with...
Geecon2022: How to avoid common mistakes and misconceptions when working with...Geecon2022: How to avoid common mistakes and misconceptions when working with...
Geecon2022: How to avoid common mistakes and misconceptions when working with...
adebski
 

Similar to Serverless in java Lessons learnt (20)

Adopting Java for the Serverless world at Serverless Meetup Singapore
Adopting Java for the Serverless world at Serverless Meetup SingaporeAdopting Java for the Serverless world at Serverless Meetup Singapore
Adopting Java for the Serverless world at Serverless Meetup Singapore
 
Adopting Java for the Serverless world at AWS User Group Pretoria
Adopting Java for the Serverless world at AWS User Group PretoriaAdopting Java for the Serverless world at AWS User Group Pretoria
Adopting Java for the Serverless world at AWS User Group Pretoria
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
NEW LAUNCH! Developing Serverless C# Applications
NEW LAUNCH! Developing Serverless C# ApplicationsNEW LAUNCH! Developing Serverless C# Applications
NEW LAUNCH! Developing Serverless C# Applications
 
Deep Dive on AWS Lambda - January 2017 AWS Online Tech Talks
Deep Dive on AWS Lambda - January 2017 AWS Online Tech TalksDeep Dive on AWS Lambda - January 2017 AWS Online Tech Talks
Deep Dive on AWS Lambda - January 2017 AWS Online Tech Talks
 
Serverless Computing
Serverless ComputingServerless Computing
Serverless Computing
 
Journey towards serverless infrastructure
Journey towards serverless infrastructureJourney towards serverless infrastructure
Journey towards serverless infrastructure
 
JDD2022: How to avoid common mistakes and misconceptions when working with Ja...
JDD2022: How to avoid common mistakes and misconceptions when working with Ja...JDD2022: How to avoid common mistakes and misconceptions when working with Ja...
JDD2022: How to avoid common mistakes and misconceptions when working with Ja...
 
A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)A 60-mn tour of AWS compute (March 2016)
A 60-mn tour of AWS compute (March 2016)
 
2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)
 
Serverless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloadsServerless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloads
 
AWS Lambda in C#
AWS Lambda in C#AWS Lambda in C#
AWS Lambda in C#
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
Aws Lambda for Java Architects - Illinois JUG-Northwest -2016-08-02
 
Deep Dive on AWS Lambda
Deep Dive on AWS LambdaDeep Dive on AWS Lambda
Deep Dive on AWS Lambda
 
Stephen Liedig: Building Serverless Backends with AWS Lambda and API Gateway
Stephen Liedig: Building Serverless Backends with AWS Lambda and API GatewayStephen Liedig: Building Serverless Backends with AWS Lambda and API Gateway
Stephen Liedig: Building Serverless Backends with AWS Lambda and API Gateway
 
Building serverless backends - Tech talk 5 May 2017
Building serverless backends - Tech talk 5 May 2017Building serverless backends - Tech talk 5 May 2017
Building serverless backends - Tech talk 5 May 2017
 
Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]
 
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
 
Geecon2022: How to avoid common mistakes and misconceptions when working with...
Geecon2022: How to avoid common mistakes and misconceptions when working with...Geecon2022: How to avoid common mistakes and misconceptions when working with...
Geecon2022: How to avoid common mistakes and misconceptions when working with...
 

Recently uploaded

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 

Recently uploaded (20)

Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 

Serverless in java Lessons learnt

  • 1. Serverless in Java Lessons learnt Krzysztof Pawlowski krzysztof.pawlowski@merapar.com JEE Conf, 27.04.2019 Kyiv
  • 2. About me • Helping clients create value with innovative cloud solutions @ Merapar • Teaching students good programming practices @ Polish- Japanese Academy of IT • 10+ years of experience with Java • 2 years of experience with AWS • Certified AWS Solutions Architect and AWS Developer
  • 3. Agenda • What is serverless? • Why did we choose serverless and Java? • What did we learn when using Java for serverless solution? • Best practices

  • 4. –Techopedia “Serverless computing is a type of cloud computing where the customer does not have to provision servers for the back-end code to run on, but (…) cloud provider starts and stops a container platform as a service as requests come (…).”
  • 5. How does serverless work? Function A Function A code / jars storage Serverless Computing Platform Execution Environment Server Execution Environment Server Execution Environment Server Execution Environment Server Client Function A 1. Execute Function A 2. Retrieve Function A 5. Return result 3. Deploy Function A 4. Run Function A
  • 6. How does serverless work? EC2 instance (server) Execution environment JVM Request Handler
  • 7. Our use-case: migration project • Migration of several million users and devices to a new platform • Users decide when they want to migrate • Users and data are migrated to a new backoffice • Firmware is upgraded • How to orchestrate the migration process?

  • 9. Why serverless? • No servers to manage • Simplified deployment and packaging (AWS Cloudformation) • Automatic continuous scaling • No idle / cold servers = no costs when not used • Pay per request • Availability and fault tolerance build in 

  • 10. Why Java? • Competencies in a team • Well tested libraries • Strongly typed language • AWS SDK for Java • Tooling: IntelliJ IDEA, Maven etc.
  • 11. Lesson 1: What should be the project structure?
  • 12. Project structure or One big Maven project Maven project per AWS Lambda
  • 13. Project structure 
 One big maven project
 
 Pros: • easier building process • code re-usage
 Cons: • longer time needed to 
 download/unpack package 
 before invocation 
 Maven project per lambda Pros: • single functionality deployment • lambda code separation / loose coupling • shorter time needed to download/ unpack package before invocation Cons: • code duplication
  • 14. Lesson 2: Where has the complexity moved to?
  • 15. Endpoint definition in Spring Boot   @RequestMapping(method = RequestMethod.POST)
 @ResponseStatus(HttpStatus.CREATED)
 @ResponseBody
 @Path(“/foo”)
 public Long create(@RequestBody Foo resource) {
       return service.create(resource);
   }
  • 16. Endpoint definition in AWS AWS IAM AWS API Gateway AWS Lambda • complexity moved from one codebase to multiple services • initial bootstrapping is more work

  • 17. Endpoint definition in AWS 1. implement AWS Lambda handler import com.amazonaws.services.lambda.runtime.Context import com.amazonaws.services.lambda.runtime.RequestHandler; public class Hello implements RequestHandler<Foo, Long> {
 public Long myHandler(Foo resource, Context context) {
 return service.create(resource);
 }
 }
  • 18. Endpoint definition in AWS 2. create API Gateway endpoint definition • a long json definition including: • OpenAPI definition (aka Swagger) of the endpoint • all responses mappings • all errors mappings
  • 19. Endpoint definition in AWS 3. create IAM role for API Gateway to call AWS Lambda "LambdaPermission": {
 "Type": "AWS::Lambda::Permission",
 "Properties": {
 "Action": "lambda:invokeFunction",
 "FunctionName": “arn:aws:lambda:<region>
 :<account-id>:function:hello”,
 "Principal": "apigateway.amazonaws.com",
 “SourceArn”:”arn:aws:execute-api:<region>
 :<account_id>:HelloApi"
 }
 }
  • 20. Developer now needs to know more about infrastructure/platform
  • 21. Lesson 3: How to debug/troubleshoot?
  • 23. Running your code locally • AWS SAM (Serverless Application Model) Local • simulates AWS cloud on your machine • Eclipse/IntelliJ plugin - possible to debug locally • not all the services are implemented
  • 24. IntelliJ AWS toolkit source: https://aws.amazon.com/blogs/developer/aws-toolkit-for-intellij-now-generally-available/
  • 25. IntelliJ AWS toolkit source: https://aws.amazon.com/blogs/developer/aws-toolkit-for-intellij-now-generally-available/
  • 26. IntelliJ AWS toolkit source: https://aws.amazon.com/blogs/developer/aws-toolkit-for-intellij-now-generally-available/
  • 27. Metrics and logs • Metrics and monitoring • CloudWatch • X-Ray
  • 28. Metrics and logs • Logs • CloudWatch
 Logs Insights • ElasticSearch / Kibana • All managed by AWS
  • 29. Lesson 4: What is the performance?
  • 30. Java performance in AWS • AWS Lambda performance test based simple application exposing GET endpoint returning “Hello world” response written in: • Java • Node.JS • C# (.net core sdk 2.0) • F# • Go • Python • Run in with 1024MB MEM • Cold start not taken into account
  • 31. Java performance in AWS Java code had average performance
  • 32. Java performance in AWS Java code had consistent performance
  • 33. Java performance in AWS Java endpoint had similar performance to other languages
  • 34. Java performance in AWS Java endpoint had a consistent performance
  • 35. Performance tuning AWS Lambda • you pay per 100 ms • price depends on amount of memory • cpu depends on amount of memory
  • 38. Lesson 5: Cold start might be an issue
  • 39. Cold start Downloading the code Starting the execution environment Bootstrapping the runtime Running the code AWS optimisation User optimisation Cold start Total execution time Warm start
  • 40. Cold start 1st call Cold start Running the code Running the code Running the code Running the code 2nd call 3rd call 4th call First execution of lambda function
  • 41. Cold start Cold start Running the code Cold start Running the code > 20..45mins Big interval between lambdas invocation
  • 42. Cold start Cold start Running the code Running the code Running the code Running the code Cold start Running the code Running the code Cold start Running the code Running the code Running the code Concurrent lambda invocations (can be limited in lambda definition) - new execution environment created
  • 43. Cold start • In case of Java cold start might take couple of seconds • Less harmful in dynamically typed languages (Python, Node.JS) • Bigger jar file increases cold start
  • 44. Decreasing cold start time • Increase memory/cpu for lambda function • might increase the cost • Separate jar file for each lambda function • Go for dynamically typed language
  • 45. Eliminating cold start time • Pre-warm lambda • call lambda every ~20 min to keep it warm (cronjob) • cost assuming 3GB mem lambda running for 1s every 20 min is about $1 per year • for n concurrent lambda executions - run at once n concurrent lambdas with the same interval
  • 46. Cold start • Other option how to handle cold start: • do nothing! • it might not be an issue in your case
  • 47. Lesson 6: Understand and use AWS best practices
  • 48. –Best Practices for Working with AWS Lambda Functions (https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html) “Take advantage of Execution Context reuse to improve the performance of your function.”
  • 49. Reusing execution context • Execution context is created during bootstrapping the environment (part of cold start) • use static initialisation/constructor, global/static variables and singletons • reuse connections: database, http, etc. • do not create long-initialised objects in the handleRequest method
  • 50. –Best Practices for Working with AWS Lambda Functions (https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html) “Use AWS Lambda Environment Variables to pass operational parameters to your function.”
  • 52. –Best Practices for Working with AWS Lambda Functions (https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html) “Be familiar with AWS Lambda Limits.”
  • 53. AWS Lambda limits • Concurrent executions: 1000 • Function timeout: 900 seconds • Function memory allocation: 128MB to 3008 MB • Function environment variables: 4KB • /tmp directory storage: 512MB
  • 54. Conclusion • Is Java good for serverless? • Definitely yes! • Is Java always good for serverless? • Definitely not!
  • 55. Conclusion • When to use serverless? • Unpredictable load of your app • Low load of the app -> low cost • No long running processes • When to use Java in serverless? • Cold start is not an issue • Java is a language of preference for the team
  • 56. Thank you!
 Q & A Krzysztof Pawlowski krzychpawlowski krzysztof.pawlowski@merapar.com