On this page

SlimFaas Functions

SlimFaas supports synchronous and asynchronous HTTP calls. This page covers synchronous invocation and shared function configuration. See Asynchronous Functions for durable queues, retries, callbacks and Dead Letter Queues.


Follow an invocation

For a synchronous call, the caller keeps its connection open while SlimFaas waits for a ready replica and proxies the response. A wake-up can therefore be visible before the first successful response.

sequenceDiagram participant Caller participant Gateway as SlimFaas proxy participant Orchestrator participant Function as HTTP function Caller->>Gateway: /function/name/path opt No ready replica Gateway->>Orchestrator: Request wake-up Orchestrator->>Function: Start replicas and check readiness end Gateway->>Function: Forward HTTP request Function-->>Gateway: Status, headers and response body Gateway-->>Caller: Stream the response

An asynchronous call separates durable acceptance from execution. See the async architecture, follow the Guided Tour, then scale out with an async burst.

1. Synchronous Functions

Synchronous calls block until the underlying function pod handles the request and returns a response.

If your function has scaled to zero, SlimFaas automatically wakes it up and waits until at least one replica is ready (subject to internal timeouts).


2. Asynchronous Functions

Calls to /async-function/{functionName}/{path} return 202 Accepted after durable enqueueing, not after execution. The dedicated Asynchronous Functions page explains concurrency, retries, deferred callbacks, and DLQ capture and replay.


Async body storage threshold

SlimFaas:AsyncBodyOffloadThresholdBytes controls where an async body is stored. At the default of 1,048,576 bytes (1 MiB), bodies up to and including 1 MiB stay in the queue entry. Bodies of 1,048,577 bytes or more use Files. The same boundary applies with Content-Length and chunked requests, including the root function route. The threshold must be positive and smaller than Array.MaxLength. The HTTP request size limit is configured separately through Kestrel:Limits:MaxRequestBodySize.

To set the recommended threshold explicitly, use this environment variable on each SlimFaas instance.

env:
  - name: SlimFaas__AsyncBodyOffloadThresholdBytes
    value: "1048576"

Lowering the threshold moves more bodies out of Raft payloads and adds Files storage and transfer work. WAL geometry and the 64 KiB queue-decoder boundary are independent of this threshold. Existing queued entries keep their stored representation and follow their queue's retry policy. Both macOS campaigns found higher throughput for some large bodies at 512 KiB. The overall comparisons missed the guardrails. Keep 1 MiB for general workloads. See the initial campaign and repeat.

3. Wake Function

You can explicitly “wake up” a function without invoking a specific route:

  • Route: POST http://<slimfaas>/wake-function/<functionName>

  • Response: 204 (No Content)

This is handy if you want to ensure the function is running before real traffic arrives.


4. Listing Functions

SlimFaas exposes a route to check the readiness status of all registered functions:

  • Route: GET http://<slimfaas>/status-functions

  • Response: An array of objects with details like NumberReady, NumberRequested, PodType, Visibility, etc.

[
    {
      "NumberReady": 1,
      "NumberRequested": 1,
      "PodType": "Deployment",
      "Visibility": "Public",
      "Name": "fibonacci1"
    }
]

5. Private vs. Public Functions

By default, functions are Public (accessible from anywhere). You can specify them as Private—restricting access to calls originating from within the same namespace.

metadata:
    annotations:
        SlimFaas/DefaultVisibility: "Private"
        # or define paths:
        SlimFaas/PathsStartWithVisibility: "Private:/mypath,Public:/otherpath"
        SlimFaas/DefaultTrusted: "Trusted"

This helps you control which services can call certain endpoints.

SlimFaas/PathsStartWithVisibility rules are evaluated in their declared order. The first matching path prefix determines visibility; matching ignores case and an optional leading /. Rules that do not match are skipped silently. If no rule matches, SlimFaas/DefaultVisibility applies (Public when omitted).

The Public: and Private: prefixes are parsed when the configuration is loaded. In status responses, each rule therefore has separate Path and Visibility fields; the prefix is not part of Path. Event subscription visibility is configured separately through SlimFaas/SubscribeEvents.

An Untrusted function will be considered as outside the namespace and will not be able to access Private actions. By default, a function is Trusted.

metadata:
    annotations:
        SlimFaas/DefaultTrusted: "Trusted" # Trusted or Untrusted

How callers are classified

A call is internal when the source address of its TCP connection is the address of a Trusted function pod or of a job pod. The comparison is exact (10.0.0.1 never matches 10.0.0.10 or 110.0.0.1), and IPv4-mapped IPv6 addresses compare equal to their IPv4 form.

The X-Forwarded-For header is ignored by default: a caller cannot become internal by forging it. If a reverse proxy sits between the callers and SlimFaas and must pass the original client address, declare it in SlimFaas:TrustedProxies (IP addresses or CIDR networks). SlimFaas then honours one hop of X-Forwarded-For, and only for connections coming from those proxies:

env:
  - name: SlimFaas__TrustedProxies__0
    value: "10.0.0.5"          # a reverse proxy with a fixed address
  - name: SlimFaas__TrustedProxies__1
    value: "10.250.1.0/28"     # a subnet reserved for the ingress controller only

Warning. TrustedProxies controls authorization, not just request attribution: every address in the list may declare any client address and therefore reach Private functions and peer endpoints on behalf of a Trusted pod. Declare only addresses owned exclusively by the proxy: its fixed IP, or a subnet that contains nothing but proxy instances. Never declare the whole pod CIDR (for example 10.244.0.0/16 on a common cluster network) or any subnet in which ordinary workloads can be scheduled; doing so reopens the header spoofing this check prevents.

Source addresses remain a weak identity: sidecars share the pod address, and a call that reaches a function pod without going through SlimFaas is not checked by SlimFaas. Use a NetworkPolicy to restrict the function ports to SlimFaas when that matters.

6. Function Configuration

You can configure the synchronous HTTP timeout and the retry policies used by asynchronous and publish calls with SlimFaas/Configuration:

{
  "DefaultSync": {
    "HttpTimeout": 120
  },
  "DefaultAsync": {
    "HttpTimeout": 120,
    "TimeoutRetries": [2,4,8],
    "HttpStatusRetries": [500,502,503,504]
  },
  "DefaultPublish": {
    "HttpTimeout": 120,
    "TimeoutRetries": [2,4,8],
    "HttpStatusRetries": [500,502,503,504]
  }
}

Synchronous calls make exactly one HTTP request and never retry. DefaultSync therefore supports only HttpTimeout. Connections from SlimFaas to function pods are recycled after five minutes when the current request finishes. This connection lifetime is independent of HttpTimeout and does not retry failed requests. Pod selection uses the latest published destination cache, including when the request captured its function configuration earlier. Connection recycling and destination-cache updates address separate parts of routing. With direct pod routing, observing a Kubernetes deletion timestamp removes that pod from new ready-target selections even if its readiness conditions still say true during graceful termination. Already active requests retain their configured timeouts. If Kubernetes discovery is unavailable, SlimFaas retains its last known snapshot until synchronization succeeds again.

TimeoutRetries defines the delays in seconds between attempts for asynchronous and publish calls. HttpStatusRetries lists the HTTP statuses that trigger those retries.

The default retry statuses include 504. An expired worker reservation or a WebSocket delivery timeout can produce that status without the function having received the message. Explicit status lists remain authoritative: include 504 when those failures should use the bounded retry budget. Enable the DLQ to retain terminal failures after that budget. Queue entries keep their acceptance-time policy; upgrading does not change old entries or reconstruct messages already evicted under a previous policy.

Every section is optional. When a section or property is omitted, SlimFaas applies its defaults. For example, the following configuration customizes only publish calls; sync and async keep their default 120-second timeout, and async keeps its default retry policy:

{
  "DefaultPublish": {
    "HttpTimeout": 15,
    "TimeoutRetries": [1,2,4],
    "HttpStatusRetries": [500,502,503]
  }
}

7. The DependsOn Annotation

You can also add a DependsOn annotation to specify that your function should wait for certain other pods to be ready before it scales up from zero. For example:

metadata:
    annotations:
        SlimFaas/Function: "true"
        SlimFaas/MinIdleReplicas: "0"
        SlimFaas/MinActiveReplicas: "1"
        # ...
        SlimFaas/DependsOn: "mysql,fibonacci2"
  • mysql and fibonacci2 are the names of other deployments/statefulsets in the same namespace.
  • SlimFaas will not scale the current function (e.g., fibonacci1) unless all pods listed in DependsOn are in a ready state and meet their own minimum replicas.

This is useful in scenarios where your function must not start until a database or another dependent function is confirmed running.

8. Scheduling Function Wake-Up and Scale-Down

Put SlimFaas/Schedule on the pod template of a Deployment or StatefulSet. Each WakeUp time counts as activity. Each ScaleDownTimeout entry selects the inactivity timeout in seconds (Value) and optional replica minimums for that part of the day.

spec:
  template:
    metadata:
      annotations:
        SlimFaas/Function: "true"
        SlimFaas/MinActiveReplicas: "2"
        SlimFaas/MinIdleReplicas: "1"
        SlimFaas/Schedule: |
          {
            "TimeZoneID": "Europe/Paris",
            "Default": {
              "WakeUp": ["08:00"],
              "ScaleDownTimeout": [
                { "Time": "09:00", "Value": 43200, "MinActiveReplicas": 3 },
                { "Time": "19:00", "Value": 3600, "MinIdleReplicas": 0 }
              ]
            }
          }
Paris time Minimum while active Minimum after inactivity Inactivity timeout
09:00–19:00 3 1 12 hours
19:00–09:00 2 0 1 hour

A window starts at its specified local time. Omitted fields use the deployment annotations or their defaults. With multiple entries, the last window continues past midnight. A single entry applies from its start until local midnight. A window change updates the minimums. WakeUp or a request through SlimFaas supplies activity. At 19:00, three busy replicas can continue serving traffic.

9. Key Annotations for Functions

Before you start calling functions, ensure you add the necessary annotations to your Kubernetes Deployments or StatefulSets:

  • SlimFaas/Function: "true" Activates SlimFaas auto-scaling and routing for this pod. Without this annotation, SlimFaas will ignore the pod.

  • SlimFaas/MinIdleReplicas: "0" The minimum number of replicas to maintain for the function. Setting 0 allows the function to scale down to zero after inactivity.

  • SlimFaas/MinActiveReplicas: "1" The minimum number of replicas while active (default 1). A request through SlimFaas can raise a function from one running replica to two.

The legacy names SlimFaas/ReplicasAtStart and SlimFaas/ReplicasMin map to the active and idle minimums respectively. SlimFaas logs a migration warning per function and old name. The new names take precedence, including inside schedule entries.

  • SlimFaas/TimeoutSecondBeforeSetReplicasMin: "300" The number of inactivity seconds after which the function will scale down to MinIdleReplicas. (Default is often 300 seconds.)

  • SlimFaas/NumberParallelRequest: "10" The maximum number of concurrent requests allowed for all replicas. Additional requests will queue until a slot frees up.

  • SlimFaas/NumberParallelRequestPerPod: "10": The maximum number of concurrent requests allowed per pod. Additional requests will queue until a slot frees up.

# Example snippet from a Deployment
metadata:
    annotations:
        SlimFaas/Function: "true"
        SlimFaas/MinIdleReplicas: "0"
        SlimFaas/MinActiveReplicas: "1"
        SlimFaas/TimeoutSecondBeforeSetReplicasMin: "300"
        SlimFaas/NumberParallelRequest: "10"
        SlimFaas/NumberParallelRequestPerPod: "10"

10. Asynchronous Function Execution: Control Callback Mode

See deferred completion callbacks for execution headers, timeout handling, and HTTP/WebSocket completion. A callback never sends a later response on the original caller connection.

Function HTTP connections have a maximum pooled age of five minutes. Expiry retires a connection after its active request/response finishes; it does not add an invocation retry. SlimData batch, file-transfer and cached cluster-peer pools use two minutes. Request deadlines and TLS opt-in settings keep their existing behavior. A pool lifetime bounds connection reuse, while Kubernetes readiness and destination-cache updates determine which pod address is selected. See the connection audit for policies and validation limits.

For Deployment and StatefulSet functions, cached destinations are invalidated by pod identity and resource-version changes as well as controller changes. A StatefulSet pod replacement or a single NotReady/terminating pod in a ready pool must not retain the previous destination list. During Kubernetes API outages the last successful snapshot remains available; successful LIST/watch recovery reconciles it with current pods. Connection expiry does not replace this refresh.

The async worker also retains local ownership when a later dequeue returns a newer reservation for an ID whose HTTP exchange is still in flight. It waits for that exchange rather than starting a parallel delivery. A terminal response completes the ID once; a nonterminal response can use the already-reserved retry without consuming it through an older failure callback. That retry waits for a ready function and keeps its original deadline. Expired reservations remain subject to the existing retry/DLQ policy, and a follower does not start them. This does not provide exactly-once execution after an unknown network outcome or leader failure. Sync invocation remains one application-level send.

Improve this page on GitHub ↗