Introducing a new way to review your PRs.

Read the announcement

floci-io / floci-az

Light, fluffy, and always free - Local Azure Emulator

View on GitHub

27 documents · Updated Nov 23, 2026

docs / storage-backends

Storage backends and runtime infrastructure

Every Azure service emulator uses shared state and runtime support. A storage backend controls whether service data stays in memory or survives a restart. Shared Docker, volume, network, TLS, and DNS services help process-based emulators run with usable endpoints in local and container environments.

Storage model

The storage model separates service behavior from durability. Services use one state contract while configuration selects the required speed and recovery trade-off.

Storage modes

ModePurposeRestart behavior
memoryFast state for development and short test runsState is lost on shutdown
persistentImmediate disk durabilityState is loaded from a JSON file and each mutation is written through
hybridFast reads with delayed persistenceState is flushed as a full snapshot at intervals, so recent writes can be lost after a crash
walFast reads with an append record for recoveryA snapshot is combined with later write records during startup

The StorageBackend contract gives services one view of these modes. Its operations cover normal reads and writes plus one-time removal, related batch changes, scans, and key lookup. A batch keeps its related puts and deletes together as one durable change.

References: src/…/StorageBackend.java• L15-45 src/…/InMemoryStorage.java• L16-65 src/…/PersistentStorage.java• L29-145 src/…/HybridStorage.java• L31-169 src/…/WalStorage.java• L51-166

Backend recovery

Each persistent mode keeps active state in memory for service reads. persistent rewrites a complete JSON view after a change. hybrid writes that view in the background after a change. wal records single changes and related batches as they happen, then replaces the record log with a fresh snapshot at intervals.

At startup, the backend loads the available disk state before the service handles requests. A hybrid store can lose changes since its last flush. A WAL store can recover changes after its latest snapshot unless the log ends with an incomplete or invalid record. A batch remains one recovery unit, so its related puts and deletes replay together.

References: src/…/PersistentStorage.java• L47-145 src/…/HybridStorage.java• L109-169 src/…/WalStorage.java• L167-237 src/…/WalStorage.java• L275-381

Backend selection

StorageFactory is the service-facing control point for storage creation. It checks a service override first and then uses the global storage mode. It gives each logical service one backend for its path, so multiple callers do not create competing state views.

Emulator configuration

Storage settings are grouped under floci-az.storage. The global mode defaults to memory, and persistent data defaults to ./data. A service can select another mode and its own flush interval. Docker-in-Docker deployments can use a separate host path for persistent data. Volume pruning is separate from file storage: it controls whether named Docker volumes are removed after a child resource is deleted.

The root floci-az settings also control the advertised host name, TLS listeners, embedded DNS, and Docker daemon. TLS can add an HTTPS listener for clients that assume port 443. DNS settings can add emulator host suffixes and control public resolver fallbacks. Docker settings identify the daemon and can isolate managed names with a namespace. Service settings can select a shared Docker network for sidecars. Together these settings let clients and spawned containers use endpoints that match their network location.

The factory maps supported service names to storage settings. It loads a backend when it creates it, reuses an existing backend for the same logical path, and manages load, flush, clear, and shutdown actions. The first backend created for a path remains active for later requests. This reuse prevents two in-memory views from writing conflicting state to the same file.

References: src/…/EmulatorConfig.java• L9-107 src/…/EmulatorConfig.java• L116-151 src/…/EmulatorConfig.java• L508-543 src/…/EmulatorConfig.java• L804-873 src/…/StorageFactory.java• L31-89 src/…/StorageFactory.java• L91-153

State persistence child page

The state persistence page describes restart recovery, snapshot timing, WAL replay, and the relationship between service records and storage files. Use it when a change affects the state life cycle rather than the shared runtime around a service.

References: src/…/StorageBackend.java• L15-45 src/…/StorageFactory.java• L49-122

Runtime container infrastructure

Some emulated services need a sidecar process instead of an in-process implementation. The shared Docker layer turns a service description into a container, starts or reuses it, manages its volumes, and returns an endpoint that fits the emulator's execution environment.

Container lifecycle

The lifecycle separates container creation from start. A service can prepare a container before it runs, and a failed start can remove the newly created resource. The manager also supports adoption, restart, stop, and removal. Labels and owner checks limit cleanup to emulator resources and protect unrelated containers.

Named volumes keep sidecar data separate from a container. The manager creates them on demand and can set root ownership and permissions for processes that do not run as root. It validates owner and permission settings before setup. Concurrent launches for the same volume wait for its one-time setup. A volume is removed after resource deletion only when storage policy and service behavior allow it.

Container labels provide both resource identity and compatibility with older managed containers. New resource labels identify the cloud, service, resource, and Azure scope. Container creation writes the supported legacy service alias with the same value. Reads accept the new label or its legacy alias, while cleanup leaves a container alone if the two values disagree.

When a start fails after creation, the newly created container is removed before the error returns. Existing containers receive more careful treatment: the manager can adopt a stopped container, and orphan cleanup removes only containers with matching emulator labels whose recorded owner is stopped or missing.

References: src/…/ContainerLifecycleManager.java• L40-193 src/…/ContainerLifecycleManager.java• L195-263 src/…/ContainerLifecycleManager.java• L291-410 src/…/ContainerLifecycleManager.java• L435-623 src/…/ContainerStorageHelper.java• L32-161

Container networking

Endpoint resolution changes with the process location and the configured endpoint mode. In native mode, the emulator normally connects through the Docker daemon host and published host ports. In container mode, it can connect to the sidecar IP on the selected Docker network. This lets the same service work when the emulator runs beside Docker or controls sibling containers through a mounted Docker socket.

When published endpoints are selected, the manager uses the Docker daemon host instead of assuming that localhost names the daemon. When automatic endpoints are selected, native callers use the published host port and container callers use the sidecar network IP and internal port. A preferred service network is used when a sidecar belongs to more than one network.

When the emulator itself runs in Docker, CurrentContainerNetworkResolver finds a usable user-defined network and its IP. The container builder can use this result so sibling containers can reach emulator endpoints. Port publishing and network attachment work together so native Docker clients keep a host endpoint while sidecars still join the service network.

References: src/…/ContainerLifecycleManager.java• L163-183 src/…/ContainerLifecycleManager.java• L451-495 src/…/ContainerLifecycleManager.java• L902-1047 src/…/CurrentContainerNetworkResolver.java• L15-25 src/…/CurrentContainerNetworkResolver.java• L40-129

Host literal formatting

Docker daemon addresses can be host names, IPv4 addresses, or IPv6 literals. Shared formatting keeps an address or certificate name bare and adds URL brackets only when the IPv6 value appears in a URL authority. This keeps endpoint, socket, and certificate data compatible.

References: src/…/HostLiterals.java• L3-27 src/…/ContainerLifecycleManager.java• L971-1017

Host port allocation

The host port allocator prevents emulator-managed services from choosing the same configured port at the same time. A free configured port is claimed once. If another service or process owns it, the caller can fall back to an OS-selected port. Cleanup releases claims so a deleted service can use its configured port again.

For a remote Docker daemon, a local free-port check cannot prove that the daemon can bind the port. The allocator reserves the configured value without probing it and lets Docker report a bind conflict. Surviving containers can restore their claims after a restart, so later allocations do not reuse their published ports.

References: src/…/PortAllocator.java• L19-43 src/…/PortAllocator.java• L45-107 src/…/PortAllocator.java• L109-139 src/…/ContainerLifecycleManager.java• L893-903

Runtime container lifecycle child page

The runtime container lifecycle page follows sidecar creation, network selection, endpoint discovery, reuse, label checks, and cleanup. Use it when a change affects a service that depends on Docker or on a container's published endpoint.

References: src/…/ContainerLifecycleManager.java• L72-160 src/…/ContainerLifecycleManager.java• L334-410 src/…/ContainerLifecycleManager.java• L497-623

TLS termination

core/tls provides the shared HTTPS boundary for clients and sidecars. When TLS is enabled, a proxy accepts the public connection and sends plain HTTP or HTTPS traffic to the matching internal Quarkus listener. Configuration can also expose a separate HTTPS listener on port 443 for clients that assume the conventional Azure endpoint port. Setting that port to zero disables the extra listener.

CertificateGenerator creates a self-signed CA certificate when no certificate is supplied. The certificate includes host names needed by local clients and function containers. Persisted certificate metadata lets startup detect a host-name change and create a new certificate instead of using one with stale names. The effective base URL can use a configured host name so service URLs work from the client network.

References: src/…/EmulatorConfig.java• L15-42 src/…/EmulatorConfig.java• L804-834

Embedded DNS

The embedded DNS service gives spawned containers a stable way to resolve emulator host names. It maps configured emulator suffixes to the emulator container IP and forwards other names to upstream resolvers. This lets sidecars use virtual-hosted Azure URLs while staying on the shared Docker network.

The resolver uses nameservers from the container's resolver settings first. Optional public fallback servers can support public host names when the primary resolver does not answer. Operators can disable those fallbacks in locked-down or offline networks. Custom suffixes extend the names that resolve to the emulator container.

References: src/…/EmulatorConfig.java• L23-24 src/…/EmulatorConfig.java• L508-543 src/…/ContainerLifecycleManager.java• L876-924

Change checklist

When these files or sections are changed, remember to consider these:

  • If StorageBackend changes, update the four backend modes and review every service that uses batch or one-time removal as a state contract.
  • If a storage mode or service name changes, update both configuration mapping and factory mode and path selection. A missing mapping can remove per-service control without a clear error.
  • If backend creation or path ownership changes, preserve one active backend per logical path and keep the first-creation rule clear when callers reuse a service.
  • If WAL records or batch records change, preserve recovery for existing files or define how old logs are handled before the next startup. Keep batch replay atomic for related puts and deletes.
  • If network selection changes, verify that native endpoints still use published host ports while container endpoints still use the selected Docker network IP.
  • If endpoint mode or Docker host resolution changes, verify that published endpoints use the daemon host and that automatic endpoints still match the caller's process location.
  • If host-port selection changes, preserve the difference between a local claim, a remote-daemon reservation, and an OS-selected port. Release claims after failed starts and resource removal.
  • If host values flow into URLs, socket addresses, or certificate names, preserve the IPv6 distinction between bracketed URL authorities and bare address literals.
  • If shared-volume ownership rules change, keep validation and one-time initialization aligned with the user and group used by each sidecar image.
  • If resource label keys change, update writers and readers together. Keep the new and legacy service labels equal, and leave conflicting labels out of cleanup decisions.
  • If DNS suffixes or fallback settings change, verify that the DNS address injected into spawned containers remains reachable and that external DNS use matches deployment policy.
  • If the advertised host name, TLS listener, or HTTPS port changes, verify that returned service URLs and certificate names still match the client network path.

Important failure modes

TriggerConsequenceGuard
A persistent JSON file cannot be readThe service can start with no state and related resources can appear missingPersistentStorage moves the unreadable file to a .corrupt path and logs the loss
A hybrid store stops before its next flushChanges since the last snapshot are lostUse persistent or wal when that loss window is not acceptable
A WAL file ends during a record or contains an unknown operationReplay stops at the bad point, so later records are not restoredWAL replay keeps entries before the error and logs the WAL path and replay count
A sidecar start fails after creationA stale container can block the next launchcreateAndStart removes the created container after a failed start
Two services request the same configured host portOne service can fail at startup or hide the requested endpointPortAllocator claims a free configured port once and lets later callers fall back to port zero
A configured port is checked on the emulator host while Docker uses a remote daemonThe reservation can describe the wrong machine and cause a bind failureRemote-daemon paths reserve the value without a local probe and let Docker validate the bind
The emulator runs in Docker but a sidecar uses another networkThe sidecar cannot reach emulator endpointsNetwork resolution prefers a usable user-defined network shared with the emulator
An IPv6 daemon address uses the wrong formURLs can be invalid or address and certificate fields can contain URL-only bracketsHostLiterals separates URL formatting from bare address formatting
A shared volume has incomplete owner settings or invalid permissionsThe sidecar can fail to write its data or the helper command can be unsafeShared-volume setup rejects partial owner pairs and validates octal permissions
A container has conflicting new and legacy service labelsCleanup or lookup can act on the wrong service identityLabel checks reject disagreement and leave the container alone

Key files

FileWhy to read it
src/…/StorageBackend.javaDefines the state contract shared by all modes
src/…/StorageFactory.javaShows mode selection, one-backend-per-path reuse, lifecycle control, and shutdown
src/…/EmulatorConfig.javaDefines global and per-service storage, Docker, TLS, and DNS settings
src/…/PersistentStorage.javaShows write-through state recovery
src/…/HybridStorage.javaShows delayed snapshot persistence
src/…/WalStorage.javaShows snapshot, single-record, batch-record, and log recovery
src/…/ContainerLifecycleManager.javaShows shared sidecar lifecycle, volume setup, label compatibility, endpoint resolution, and Docker host handling
src/…/ContainerStorageHelper.javaShows resource naming, volume mode and pruning policy, resource labels, and legacy label compatibility
src/…/HostLiterals.javaShows the shared IPv6 formatting contract for URLs and address fields
src/…/PortAllocator.javaShows configured-port claims, remote-daemon reservations, range allocation, and claim release
src/…/CurrentContainerNetworkResolver.javaShows how an in-container emulator finds the network for sibling sidecars