﻿# Prefect SERIALIZABLE needs a shared lock boundary

Prefect SERIALIZABLE coordinates work through a result-key lock manager; matching cache keys on separate workers do not create shared locking by themselves.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-prefect-serializable-shared-lock/
Language: en

## Start with concurrent work for the same source

Separate workers can receive the same expensive document-analysis request before either has stored a result. Equal cache keys identify equivalent work, but identification alone does not stop simultaneous execution. Prefect's [transaction implementation](https://raw.githubusercontent.com/PrefectHQ/prefect/main/src/prefect/transactions.py) provides a SERIALIZABLE isolation path that acquires a key-specific lock before checking whether a result record already exists. This changes the competition around that record.

## Treat lock support as required configuration

The [ResultStore implementation](https://raw.githubusercontent.com/PrefectHQ/prefect/main/src/prefect/results.py) reports SERIALIZABLE support when a lock manager is configured. Transaction preparation checks this support and rejects an unsupported configuration. Selecting the isolation label is therefore insufficient. Determine which store and manager the task will actually use, including environment-specific configuration, rather than assuming a notebook setting describes every deployed worker's effective transaction resources.

## Make the coordination boundary concrete

The official [filesystem lock manager](https://raw.githubusercontent.com/PrefectHQ/prefect/main/src/prefect/locking/filesystem.py) creates lock files under its resolved lock directory. Identical directory text on independent machines does not by itself mean they access the same files. A local manager can coordinate appropriate local processes, while separate hosts need a coordination arrangement covering their competition. Check the storage topology and manager's documented scope before claiming mutual exclusion across workers.

## Keep keys and external effects in the design

The transaction takes its lock for the configured key. Different keys do not become one serialized operation simply because their requests modify the same external resource. Conversely, an excessively broad key can serialize unrelated analysis. Define equivalence around the reusable result, then examine separately any remote action the task performs. [Task contracts](/journal/learn-codex-task-contract/) should name the actual deliverable and affected resource, rather than substituting a cache configuration for that description.

## Inspect waiting and reuse as separate outcomes

For a contention example, observe whether a competing task waited, whether a committed record became available and whether another analysis actually executed. Those events answer different questions. [Tool observations](/journal/learn-codex-tool-observation/) provide a useful record of the distinction. A sound explanation identifies the lock manager, result key and shared resources that made serialization possible; it does not infer distributed coordination solely from an isolation-level name in source code.
