The Road to Serverless: Spring Cloud Function

@david_syer, 2017

Agenda

  • 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

service-block-architecture

Amazon Lambda

aws_lambda_screenshot

Google Cloud Function

gcp_function_screenshot

Microsoft Azure Functions

azure_function_screenshot

Riff

riff_function_screenshot

Serverless Providers

  • (J) Amazon Lambda
  • Google Cloud Functions
  • (J) Azure Function
  • (J) IBM OpenWhisk
  • (J) Oracle Fn
  • OpenFaaS
  • Fission
  • Kubeless
  • (J) Riff https://github.com/projectriff
  • …​

(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

@SpringBootApplication
public class Application {

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

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

Plain Old Functions

package functions;

public class Uppercase implements Function<String, String> {

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

}

Spring Cloud Function Web

function_demo_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

@SpringBootApplication
public class Application {

  @Bean
  public Function<Flux<String>, Flux<String>> uppercase() {
    return flux -> flux
        .filter(this::isNotRude)
        .map(String::toUpperCase);
  }

  boolean isNotRude(String word) {
    ...
  }

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

Spring Cloud Function Stream

function_demo_stream

Spring Cloud Function Adapter

function_demo_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

/