The Road to Serverless: Spring Cloud Function

@david_syer, 2017


  • Serverless and functions
  • Spring Cloud Function
  • Raising the value line

Serverless and Functions

  • Event driven
  • Dynamic resource utilization
  • Billing per message
  • Prototypes become production code really quickly
  • Focus on business logic

Business Logic and the Value Line


Get out of the business of infrastructure and
automation (a.k.a. "undifferentiated heavy lifting")
and integration spaghetti


Amazon Lambda


Google Cloud Function


Microsoft Azure Functions




Serverless Providers

  • (J) Amazon Lambda
  • Google Cloud Functions
  • (J) Azure Function
  • (J) IBM OpenWhisk
  • (J) Oracle Fn
  • OpenFaaS
  • Fission
  • Kubeless
  • (J) Riff
  • …​

(J) = native Java support
Others can run Java, e.g. via custom container or node JRE launcher.

Java Util Function

public interface Function<T, R> {
    R apply(T t);

public interface Consumer<T> {
    void accept(T t);

public interface Supplier<T> {
    T get();

Spring Cloud Function

public class Application {

  public Function<String, String> uppercase() {
    return value -> value.toUpperCase();

  public static void main(String[] args) {, args);

Plain Old Functions

package functions;

public class Uppercase implements Function<String, String> {

  String apply(String input) {
    return input.toUpperCase();


Spring Cloud Function Web


Spring Cloud Function

All the benefits of serverless, but with full access to Spring (dependency injection, integrations, autoconfiguration) and build tools (testing, continuous delivery, run locally)

For Spring devs: a smaller, more familiar step than using FaaS APIs and UIs natively

For Functionistas: no need to know anything about Spring

Decouple lifecycle of business logic from runtime platform. Run the same code as a web endpoint, a stream processor, or a task

Uniform programming model across serverless providers, and also able to run standalone (locally or in a PaaS)

Project Reactor

public abstract class Flux<T> implements Publisher<T> {

public abstract class Mono<T> implements Publisher<T> {

Spring Cloud Function

public class Application {

  public Function<Flux<String>, Flux<String>> uppercase() {
    return flux -> flux

  boolean isNotRude(String word) {

  public static void main(String[] args) {, args);

Spring Cloud Function Stream


Spring Cloud Function Adapter


Spring Cloud Function

  1. Programming model: @Beans of type Function, Consumer and Supplier
  2. Component scan for functions (e.g. execute jar with no dependency on Spring at all)
  3. Compile strings which are Java function bodies
  4. Bind and invoke from an isolated classloader (JVM packing, platform)
  5. Adapters for AWS Lambda, Azure, Riff and other "serverless" service providers