Skip to main content

Serverless vs. Persistent Servers

Leapcell offers two primary deployment modes to cater to diverse application needs: Serverless (Pay-as-you-go) and Persistent (Charge-by-time).

tip

On Leapcell, your service can switch between Serverless and Persistent Server modes at any time. You can choose the mode that best fits your specific use case.

Understanding their distinct features and trade-offs will help you choose the most suitable option for your project.

Serverless (Pay-as-you-go)

Serverless Cost

The Serverless mode is an event-driven computing model where you only pay for the time your code is actively running.

Billing starts when a request is received and ends once the request has been fully processed. You incur no costs for idle time when your application is not serving traffic.

Serverless Active Time

Automatic Scaling

The platform automatically scales the number of instances up or down based on traffic volume.

It can scale to thousands of instances to effortlessly handle traffic spikes.

Serverless Scaling
Cold Starts

If your service receives no traffic for a period (e.g., 30 minutes), its instances may go dormant. A new incoming request will trigger a "cold start" to provision a new instance, which can add a latency of up to 250ms. Services with consistent traffic rarely encounter this.

Serverless Cold Start

Serverless Advantages and Limitations

Key Advantages

AdvantageDescription
Cost-EffectiveEliminates charges for idle resources, making it ideal for applications with variable or unpredictable traffic patterns.
Automatic ScalingThe platform automatically scales the number of instances up or down based on traffic volume. It can scale to thousands of instances to effortlessly handle traffic spikes.

Limitations to Consider

LimitationDescription
HTTP Short-Lived Requests OnlyThe Serverless model is optimized for short-lived HTTP requests. It is not suitable for long-running connections such as WebSockets, long-polling, or background jobs.
Temporary File SystemOnly the /tmp directory is writable. All other paths in the file system are read-only.
Request TimeoutThe maximum execution time for a single request is 15 minutes.
CPU SuspensionDuring idle periods, the instance's CPU is suspended. This means it cannot run any background tasks when there are no incoming requests.

Persistent Mode (Charge-by-time)

Persistent Server

The Persistent mode provides you with a dedicated, continuously running instance, much like a local machine or a traditional cloud server.

It remains active and ready to serve traffic at all times, regardless of inbound request volume. This mode is billed based on a fixed time interval, such as per hour or per month.

Key Advantages:

FeatureDescription
Cheaper per Unit TimeThe fixed billing model can be more cost-effective for applications with steady workloads. For more details, see Leapcell Pricing.
No Cold StartsThe instance is always active, ensuring the lowest possible latency for every request.
File SystemOffers a writable file system beyond the /tmp directory, allowing for local file I/O, caching, and state management.
Long-Running TasksIdeal for processes that need to run for extended periods without being suspended, such as background jobs, data processing, or maintaining persistent connections (e.g., WebSockets).

Serverless or Persistent for my use case?

tip

For most use cases, we recommend starting with the Serverless mode due to its excellent flexibility and cost efficiency.

When to Use Serverless

When to Use ServerlessDescription
Any stateless HTTP or web serviceYour application state should be stored in object storage or a database, not in the service itself.
Services with unpredictable early-stage trafficIn the early stage, when traffic is low or uncertain, the Serverless model is the most cost-efficient choice.

When to Use Persistent Servers

The Persistent mode is the superior choice in the following scenarios:

When to Use Persistent ServersDescription
High and Sustained TrafficIf your service consistently handles high traffic, the cost-per-hour of a Persistent instance may be lower than the cumulative cost of frequent Serverless invocations.
Long-Running Background JobsFor tasks that exceed the 15-minute limit, such as video encoding, complex data analysis, or training machine learning models.
Dependency on Local File SystemWhen your application requires persistent local storage beyond /tmp, such as for caching or state management.
Ultra-Low Latency RequirementsIdeal for applications where even minimal latency from occasional cold starts is unacceptable.
WebSockets or Long-Lived ConnectionsIf your service requires WebSockets or other long-lived connections, you must use Persistent Servers.