Streaming Overview

EDJX currently supports the building, management, and deployment of Rust and C++ based serverless functions. Additionally, developers can use the streaming feature while building serverless functions. This feature optimizes data transfer (upload file/download file) to the EDJX object storage, and HTTP transfers. Using the streaming feature, developers can work with large data sets without allocating huge memory to the functions. Since functions process data as smaller chunks, the use of streaming in functions drastically reduces the response time.

To use streaming for serverless functions, refer to the following documentations:

For step-by-step instructions on how to build serverless functions using streaming, refer to the Rust Tutorial and C++ Tutorial.

Streaming Components

Streaming is composed of the following components:

  • Chunk: Represents a single piece of data written to or read from a stream of data. A stream can contain chunks of different types of data.

  • ReadStream: Represents the source of data. In a ReadStream, chunks are queued and read one at a time from the data source.

  • WriteStream: Represents the destination of data. In a WriteStream, chunks are passed one at a time and written to the destination.

  • Pipes: Represents the binding of ReadStream and WriteStream together. A ReadStream can be piped directly to a WriteStream.

How Streaming Works?

A streaming function receives the request in chunks and returns the output in chunks. Once the chunk of data is processed, the memory occupied by the chunk is released, resulting in optimal memory performance.

lib.cpp/ needs to be updated if a serverless function sends HTTP Response using streams. Refer to the sample template. The default lib.cpp/ template can be used if the HTTP Response is sent without using streams.

Comparative Analysis - Streaming vs. Non-Streaming in Functions

One of the main functionality in EDJX serverless functions is to work with HTTP using EdjLibrary SDK. Since HTTP is a stateless protocol, therefore in a function, multiple combinations of streaming and non-streaming modes can exist. It is the choice of the developer to choose between the streaming or the non-streaming mode for an HTTP API.

Functions with Streaming Functions without Streaming

The read and write operations are in chunks

The read and write operations are as a single request/response

Requires less memory since data is being processed incrementally

Requires more memory for the entire data to be processed

Provides real-time capability and higher performance

Comparatively, low performance since large data is processed and sent back resulting in more time

Memory is released as soon as the chunk is processed

Memory is captured until the whole data set is processed

Benefits of Streaming

A few benefits of using streaming in serverless functions are:

  • Promotes quick processing since the processing of data can start as soon as it is available, and does not have to wait until all data is loaded into memory.

  • Enables streaming of large data.

  • Overcomes the memory constraints by supporting “large buffers”.

  • Promotes incremental data processing.

  • Easy implementation by using ReadStreams and WriteStreams in Functions.

  • Supports piping that creates pipes between ReadStreams and WriteStreams. This enables developers to develop functions with very simple code.

Use Cases

Some possible use case scenarios are as follows:

  • Piping a ReadStream from EDJX Serverless Function HTTP Request to EDJX Storage.

  • Piping a ReadStream from an HTTP Response to EDJX Storage.

  • Piping a ReadStream from an HTTP Response to EDJX Serverless Function HTTP Response.

  • Piping a ReadStream from EDJX Storage File to an HTTP Request.

Streaming is also supported for the following:

  • HTTP request and response between the client (user) and the serverless function.

  • HTTP request and response between the serverless function and a third-party Web server.

  • Data transfer between the serverless function and the EDJX Storage.

Any of the three types of streams can be piped into each other.