Skip to main content
XenonStack

Serverless

XenonStack Blog OpenFaaS with Java: Serverless Functions on Kubernetes

and | Published | Updated

OpenFaaS with Java: Serverless Functions on Kubernetes
9:46

Key takeaway

  • OpenFaaS with Java explained for enterprise teams: editions, of-watchdog, faas-cli deployment, async calls, autoscaling, and when functions beat services.

OpenFaaS is an open-source framework that turns a container, or a small piece of code, into a serverless function you can call over HTTP on Kubernetes. Java works well with it, because the function runs as an ordinary container process, so you keep your language, build tools and libraries. For leaders, the decision is rarely about Java itself. It is about which edition fits production, who owns scaling and security, and which workloads suit short-lived functions.

This guide explains how OpenFaaS works, how a Java function is built and deployed with faas-cli, and when functions are the wrong choice. It sits beside our guides to Function as a Service and serverless Java microservices, and takes the OpenFaaS and Kubernetes angle. Product facts below come from the OpenFaaS documentation and repositories, read on 13 November 2026.

What is OpenFaaS and which edition should an enterprise use?

According to its docs, OpenFaaS makes it easy to deploy event-driven functions and microservices to Kubernetes, and you package your code or an existing binary in a Docker image. Functions are small, single-purpose units, so they suit glue code, integrations and event handlers better than large stateful systems.

Edition choice matters before any code is written. According to the OpenFaaS docs, the editions are:

EditionIntended use (per OpenFaaS docs)Runs on
Community Edition (CE)Free for personal use, with a 60-day limit for commercial use. The repository README describes it as licensed for individual exploration and hobbyist use.Kubernetes
Standard / For Enterprises (OpenFaaS Pro)Commercial use and production, built specifically for production.Kubernetes
faasdFree to use on any cloud or on-premises, on a single VM without clustering or Kubernetes.A single VM

Treat CE as a proof-of-concept tool and check the licence terms on the official page before a business team adopts it.

How do OpenFaaS functions run on Kubernetes?

A function is a container image with a watchdog process inside it. The gateway gives each function a route, forwards HTTP requests to it and exposes metrics that autoscaling can use. This is the same container-and-orchestrator model described in our guide to Kubernetes architecture components.

Two-column diagram: faas-cli new, build and push, deploy, and invoke on the left; template wrapper, registry image, gateway routing, and scaling and queue on the right.
ComponentRoleSource
GatewayReceives calls on /function/NAME (synchronous) or /async-function/NAME (asynchronous) and routes them to the function.OpenFaaS async docs
Watchdog (of-watchdog)Runs inside the container as the entry point, with an embedded HTTP server written in Go that starts and monitors the function process.OpenFaaS watchdog docs
faas-cliBuilds, pushes and deploys functions from templates and a stack file.faas-cli README
Prometheus metricsAutoscaling rules read load from Prometheus. The Pro autoscaler can use any custom metric available there.OpenFaaS autoscaling docs

What is the difference between the classic watchdog and of-watchdog?

According to the OpenFaaS docs, the classic watchdog forks one process per request, which gives the highest portability. The of-watchdog can keep the function process warm between invocations, which helps with costly resources such as database connection pools or models. For Java this matters most, because JVM start-up is expensive and a per-request fork would repeat it.

In the of-watchdog repository, HTTP mode (mode=http) is described as set to become the default for future templates, and the fprocess variable names the process to run. Afterburn mode is marked deprecated in favour of HTTP mode, so new work should use HTTP mode.

How do you build and deploy a Java function with faas-cli?

The faas-cli README lists the commands that matter: new creates a function from a template, build creates a Docker image, push sends the image to a registry, deploy releases it to a local or remote gateway, invoke calls it, and login and logout store or remove gateway credentials. Templates are fetched from the template store when you run new or build, and third-party templates are added with template pull.

For Java, the CLI template documentation lists java21-vertx, a Java 21 Vert.x template, in the store. The official templates repository also lists a Java 11 template marked deprecated, so pick a current long-term-support Java version and confirm the template list on the official page before you start.

faas-cli template store list
faas-cli new --lang java21-vertx hello-java
faas-cli build -f hello-java.yml
faas-cli push -f hello-java.yml
faas-cli deploy -f hello-java.yml

The handler is the only code you write. The template wraps it in an HTTP server and the watchdog, builds the image and keeps the function contract the same across languages.

Video: OpenFaaS with Java, from XenonStack.

When should you use asynchronous invocation?

According to the OpenFaaS docs, any function can be invoked asynchronously by changing the gateway route to /async-function/NAME. The gateway queues the request on NATS JetStream, returns 202 Accepted and a queue worker calls the function later, so the caller does not wait. Results can be sent to a URL supplied in the X-Callback-Url header, which carries the original X-Call-Id. The docs give a 1MB maximum payload, and recommend restricting callbacks to trusted endpoints in production. For larger data, store it elsewhere and pass an identifier.

Use it for batch jobs, image or video conversion and work that can wait. Keep synchronous calls for short request and response APIs.

How does OpenFaaS scale, and what changes between editions?

The OpenFaaS autoscaling docs describe two models. The legacy model uses a single AlertManager rule over requests per second, and the docs state that CE is meant for development or internal non-business use. The Pro autoscaler runs Prometheus queries on a schedule, scales between a minimum and maximum replica count or to zero, and supports rps, capacity, cpu, queue and custom rules. Scale to zero is opt-in per function through a label and is a Pro feature.

Serverless functions or microservices: which fits?

Functions do not replace monoliths or microservices. They work best beside them, handling integrations and moving events between systems. The table gives a starting rule.

WorkloadFunctions fit whenPrefer a service when
Event handlers and integrationsWork is short, stateless and triggered by events.The handler needs long-lived state or many dependencies.
Batch and conversion jobsWork can run asynchronously and be retried.Jobs need strict ordering across steps.
HTTP APIsTraffic is bursty and each call is small.You need steady low latency and tuned JVM settings.
Core business logicRarely the first choice.Logic is large, stateful and shared across teams.

For related reading, see serverless for big data, AWS Lambda and serverless architecture and Google Cloud serverless computing.

What should governance, security and cost cover?

  • Licensing: confirm the edition and its commercial terms before production use.
  • Access: store gateway credentials with faas-cli login, and restrict async callback URLs to trusted endpoints.
  • Images: build functions from approved base images and scan them like any container.
  • Cost: measure JVM start-up and memory per function, because warm Java processes cost more per replica than small runtimes.
  • Observability: use Prometheus metrics to see which functions scale and why.

The same questions apply when functions become tools for AI agents. ElixirClaw is an agentic OS platform to build, orchestrate and govern AI agents and automation workflows while keeping humans in control, and Elixir Govern (formerly AgentGRC) keeps autonomous agent actions inside policy, with the audit trail risk teams need. See also our guide to agentic workflows.

What is a sensible adoption sequence?

  1. Confirm the edition and licence for your use.
  2. Deploy to a test Kubernetes cluster and run one Java function from the store template.
  3. Measure start-up time, memory and latency on a real workload.
  4. Add async processing for work that can wait.
  5. Set scaling rules, access controls and image checks before wider rollout.

To map one function-based workflow your agents should run, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.

FAQ

What is OpenFaaS used for?

According to its docs, OpenFaaS deploys event-driven functions and microservices to Kubernetes by packaging code or an existing binary in a Docker image.

Can OpenFaaS CE be used in production?

The docs describe CE as free for personal use with a 60-day limit for commercial use, and list Standard or For Enterprises as the edition for commercial production. Confirm the terms on the official page.

Which Java template should I use?

The CLI template docs list java21-vertx, a Java 21 Vert.x template, in the template store. The official templates repository marks its Java 11 template as deprecated.

What is the difference between synchronous and asynchronous calls?

Synchronous calls use /function/NAME and wait for the response. Asynchronous calls use /async-function/NAME, return 202 Accepted and run through a NATS JetStream queue, with optional results sent to an X-Callback-Url.

Does OpenFaaS scale to zero?

According to the autoscaling docs, scale to zero is opt-in per function through a label and is described under the Pro autoscaler. CE uses the legacy AlertManager rule.

Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

LinkedIn profile

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Get the latest articles in your inbox

Subscribe Now

Interested in solving your challenges with the XenonStack team?
Get Started

Tell us about you and your priorities so we can prepare the right conversation. It takes about 2 minutes.

Please Select your Industry
Banking
Fintech
Payment Providers
Wealth Management
Discrete Manufacturing
Semiconductor
Machinery Manufacturing / Automation
Appliances / Electrical / Electronics
Elevator Manufacturing
Defense & Space Manufacturing
Computers & Electronics / Industrial Machinery
Motor Vehicle Manufacturing
Food and Beverages
Distillery & Wines
Beverages
Shipping
Logistics
Mobility (EV / Public Transport)
Energy & Utilities
Hospitality
Digital Gaming Platforms
SportsTech with AI
Public Safety - Explosives
Public Safety - Firefighting
Public Safety - Surveillance
Public Safety - Others
Media Platforms
City Operations
Airlines & Aviation
Defense Warfare & Drones
Robotics Engineering
Drones Manufacturing
AI Labs for Colleges
AI MSP / Quantum / AGI Institutes
Retail Apparel and Fashion

Continue