SlideShare a Scribd company logo
Serverless in Java
Lessons learnt
Krzysztof Pawlowski
krzysztof.pawlowski@merapar.com
Confitura, 29.06.2019 Warsaw
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 handleRequest(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
• not all the services are
implemented
• Eclipse/IntelliJ plugin - possible to
debug locally
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
Reducing cold start time using AWS Lambda Layers
• AWS Lambda Layers
• libraries
• custom runtime
• other dependencies
source: https://aws.amazon.com/blogs/compute/working-with-aws-lambda-and-lambda-layers-in-aws-sam/
Reducing cold start time using AWS Lambda Layers
source: https://github.com/bertjan/graal-native-image-aws-lambda
Execution environment
• GraalVM - polyglot VM with
short startup time and low
memory footprint
• Vert.x - event-driven, non-
blocking toolkit for building
reactive applications
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
We’re hiring!



jobs.pl@merapar.com
Thank you!

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

More Related Content

What's hot (7)

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
 
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
 
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
 
Continuous Delivery in the AWS Cloud
Continuous Delivery in the AWS CloudContinuous Delivery in the AWS Cloud
Continuous Delivery in the AWS Cloud
Nigel Fernandes
 
Docker and java
Docker and javaDocker and java
Docker and java
Anthony Dahanne
 
ECS and ECR deep dive
ECS and ECR deep diveECS and ECR deep dive
ECS and ECR deep dive
Shiva Narayanaswamy
 
Jeffrey Richter
Jeffrey RichterJeffrey Richter
Jeffrey Richter
CodeFest
 
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
 
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
 
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
 
Continuous Delivery in the AWS Cloud
Continuous Delivery in the AWS CloudContinuous Delivery in the AWS Cloud
Continuous Delivery in the AWS Cloud
Nigel Fernandes
 
Jeffrey Richter
Jeffrey RichterJeffrey Richter
Jeffrey Richter
CodeFest
 

Similar to Serverless in Java Lessons learnt (20)

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
 
Adopting Java for the Serverless World at VoxxedDays Luxemburg
Adopting Java for the Serverless World at VoxxedDays LuxemburgAdopting Java for the Serverless World at VoxxedDays Luxemburg
Adopting Java for the Serverless World at VoxxedDays Luxemburg
Vadym Kazulkin
 
Adopting Java for the Serverless world at Serverless Meetup Italy
Adopting Java for the Serverless world at Serverless Meetup ItalyAdopting Java for the Serverless world at Serverless Meetup Italy
Adopting Java for the Serverless world at Serverless Meetup Italy
Vadym Kazulkin
 
Adopting Java for the Serverless World at JAX 2022
Adopting Java for the Serverless World at JAX 2022Adopting Java for the Serverless World at JAX 2022
Adopting Java for the Serverless World at JAX 2022
Vadym Kazulkin
 
Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022
Vadym Kazulkin
 
Adopting Java for the Serverless World at JUG Bonn 2022
Adopting Java for the Serverless World at JUG Bonn 2022Adopting Java for the Serverless World at JUG Bonn 2022
Adopting Java for the Serverless World at JUG Bonn 2022
Vadym Kazulkin
 
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 JUG Hessen 2022
Adopting Java for the Serverless World at JUG Hessen 2022Adopting Java for the Serverless World at JUG Hessen 2022
Adopting Java for the Serverless World at JUG Hessen 2022
Vadym Kazulkin
 
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
 
Adopting Java for the Serverless world at Serverless Meetup New York and Boston
Adopting Java for the Serverless world at Serverless Meetup New York and BostonAdopting Java for the Serverless world at Serverless Meetup New York and Boston
Adopting Java for the Serverless world at Serverless Meetup New York and Boston
Vadym Kazulkin
 
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
Vadym Kazulkin
 
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Vadym Kazulkin
 
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin
 
High performance Serverless Java on AWS- Serverless Architecture Javaland 2025
High performance Serverless Java on AWS- Serverless Architecture Javaland 2025High performance Serverless Java on AWS- Serverless Architecture Javaland 2025
High performance Serverless Java on AWS- Serverless Architecture Javaland 2025
Vadym Kazulkin
 
How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...
Vadym Kazulkin
 
Kotlin for backend using serverless + aws lambda
Kotlin for backend using serverless + aws lambdaKotlin for backend using serverless + aws lambda
Kotlin for backend using serverless + aws lambda
Bert Añasco
 
High performance Serverless Java on AWS at We Are Developers 2024
High performance Serverless Java on AWS at We Are Developers 2024High performance Serverless Java on AWS at We Are Developers 2024
High performance Serverless Java on AWS at We Are Developers 2024
Vadym Kazulkin
 
Building self service framework
Building self service frameworkBuilding self service framework
Building self service framework
Rovshan Musayev
 
High performance Serverless Java on AWS- Serverless Architecture Conference B...
High performance Serverless Java on AWS- Serverless Architecture Conference B...High performance Serverless Java on AWS- Serverless Architecture Conference B...
High performance Serverless Java on AWS- Serverless Architecture Conference B...
Vadym Kazulkin
 
Containerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS LambdaContainerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS Lambda
Ryan Cuprak
 
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
 
Adopting Java for the Serverless World at VoxxedDays Luxemburg
Adopting Java for the Serverless World at VoxxedDays LuxemburgAdopting Java for the Serverless World at VoxxedDays Luxemburg
Adopting Java for the Serverless World at VoxxedDays Luxemburg
Vadym Kazulkin
 
Adopting Java for the Serverless world at Serverless Meetup Italy
Adopting Java for the Serverless world at Serverless Meetup ItalyAdopting Java for the Serverless world at Serverless Meetup Italy
Adopting Java for the Serverless world at Serverless Meetup Italy
Vadym Kazulkin
 
Adopting Java for the Serverless World at JAX 2022
Adopting Java for the Serverless World at JAX 2022Adopting Java for the Serverless World at JAX 2022
Adopting Java for the Serverless World at JAX 2022
Vadym Kazulkin
 
Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022
Vadym Kazulkin
 
Adopting Java for the Serverless World at JUG Bonn 2022
Adopting Java for the Serverless World at JUG Bonn 2022Adopting Java for the Serverless World at JUG Bonn 2022
Adopting Java for the Serverless World at JUG Bonn 2022
Vadym Kazulkin
 
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 JUG Hessen 2022
Adopting Java for the Serverless World at JUG Hessen 2022Adopting Java for the Serverless World at JUG Hessen 2022
Adopting Java for the Serverless World at JUG Hessen 2022
Vadym Kazulkin
 
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
 
Adopting Java for the Serverless world at Serverless Meetup New York and Boston
Adopting Java for the Serverless world at Serverless Meetup New York and BostonAdopting Java for the Serverless world at Serverless Meetup New York and Boston
Adopting Java for the Serverless world at Serverless Meetup New York and Boston
Vadym Kazulkin
 
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
Vadym Kazulkin
 
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Vadym Kazulkin
 
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin
 
High performance Serverless Java on AWS- Serverless Architecture Javaland 2025
High performance Serverless Java on AWS- Serverless Architecture Javaland 2025High performance Serverless Java on AWS- Serverless Architecture Javaland 2025
High performance Serverless Java on AWS- Serverless Architecture Javaland 2025
Vadym Kazulkin
 
How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...
Vadym Kazulkin
 
Kotlin for backend using serverless + aws lambda
Kotlin for backend using serverless + aws lambdaKotlin for backend using serverless + aws lambda
Kotlin for backend using serverless + aws lambda
Bert Añasco
 
High performance Serverless Java on AWS at We Are Developers 2024
High performance Serverless Java on AWS at We Are Developers 2024High performance Serverless Java on AWS at We Are Developers 2024
High performance Serverless Java on AWS at We Are Developers 2024
Vadym Kazulkin
 
Building self service framework
Building self service frameworkBuilding self service framework
Building self service framework
Rovshan Musayev
 
High performance Serverless Java on AWS- Serverless Architecture Conference B...
High performance Serverless Java on AWS- Serverless Architecture Conference B...High performance Serverless Java on AWS- Serverless Architecture Conference B...
High performance Serverless Java on AWS- Serverless Architecture Conference B...
Vadym Kazulkin
 
Containerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS LambdaContainerless in the Cloud with AWS Lambda
Containerless in the Cloud with AWS Lambda
Ryan Cuprak
 
Ad

Recently uploaded (20)

Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Aaryan Kansari
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Introducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRCIntroducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRC
Adtran
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AI Emotional Actors:  “When Machines Learn to Feel and Perform"AI Emotional Actors:  “When Machines Learn to Feel and Perform"
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AkashKumar809858
 
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Peter Bittner
 
SDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhereSDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhere
Adtran
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Agentic AI Explained: The Next Frontier of Autonomous Intelligence & Generati...
Aaryan Kansari
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Securiport - A Border Security Company
Securiport  -  A Border Security CompanySecuriport  -  A Border Security Company
Securiport - A Border Security Company
Securiport
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Introducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRCIntroducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRC
Adtran
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AI Emotional Actors:  “When Machines Learn to Feel and Perform"AI Emotional Actors:  “When Machines Learn to Feel and Perform"
AI Emotional Actors: “When Machines Learn to Feel and Perform"
AkashKumar809858
 
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Peter Bittner
 
SDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhereSDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhere
Adtran
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
Ad

Serverless in Java Lessons learnt

  • 1. Serverless in Java Lessons learnt Krzysztof Pawlowski [email protected] Confitura, 29.06.2019 Warsaw
  • 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 handleRequest(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 • not all the services are implemented • Eclipse/IntelliJ plugin - possible to debug locally
  • 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. Reducing cold start time using AWS Lambda Layers • AWS Lambda Layers • libraries • custom runtime • other dependencies source: https://aws.amazon.com/blogs/compute/working-with-aws-lambda-and-lambda-layers-in-aws-sam/
  • 47. Reducing cold start time using AWS Lambda Layers source: https://github.com/bertjan/graal-native-image-aws-lambda Execution environment • GraalVM - polyglot VM with short startup time and low memory footprint • Vert.x - event-driven, non- blocking toolkit for building reactive applications
  • 48. Cold start • Other option how to handle cold start: • do nothing! • it might not be an issue in your case
  • 49. Lesson 6: Understand and use AWS best practices
  • 50. –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.”
  • 51. 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
  • 52. –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.”
  • 54. –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.”
  • 55. 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
  • 56. Conclusion • Is Java good for serverless? • Definitely yes! • Is Java always good for serverless? • Definitely not!
  • 57. 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
  • 59. Thank you!
 Q & A Krzysztof Pawlowski krzychpawlowski [email protected]