In this lesson, you will learn how to configure Fluent Bit’s memory and filesystem buffering to ensure log integrity during traffic spikes or temporary downstream outages.
When your logging backend (like Elasticsearch or an S3 bucket) experiences high latency or downtime, your log forwarder—Fluent Bit—can quickly run out of memory if it tries to hold too many logs in RAM. If the buffer overflows, the default behavior is often to drop incoming logs to protect the system’s stability. To prevent this data loss, we can implement a tiered buffering strategy that spills over from memory to disk.
Configuring Memory and Filesystem Buffering
In your Fluent Bit configuration, you define buffering at the [OUTPUT] section level. By setting a mem_buf_limit, you cap the amount of RAM the instance uses per output. When this limit is hit, you can force the agent to store chunks on the disk instead of dropping them, using the storage.type and storage.path settings.
Here is an example configuration for a robust output plugin:
[OUTPUT]
Name es
Match *
Host elasticsearch
# Cap memory usage for this output to 5MB
mem_buf_limit 5MB
# Enable persistent storage to avoid data loss
storage.type filesystem
[SERVICE]
# Define where the buffered chunks are stored on the node
storage.path /var/log/flb-storage/
storage.sync normal
storage.checksum on
How it works
- Memory Buffer: Fluent Bit caches incoming logs in memory for speed. If you set
mem_buf_limitto5MB, the engine will attempt to process logs from memory as fast as possible. - Filesystem Spillover: By enabling
storage.type filesystem, once the 5MB memory limit is reached, Fluent Bit stops accumulating new data in RAM and begins writing log chunks directly to the/var/log/flb-storage/directory on the node. - Resilience: If the downstream service (e.g., Elasticsearch) stays down for an hour, your logs remain safely queued on the disk. Once the service recovers, Fluent Bit automatically reads the stored files and flushes them to the destination, effectively "catching up."
Key Takeaway: By capping memory usage and enabling filesystem storage, you create a safety net that protects your log data during traffic bursts and prevents loss during downstream outages.