# Principle: Separate Before Serializing Shared State

Ensure that parallel actors writing to the same target are separated first, and only serialize access when a shared write target is an invariant.

**Canonical URL:** https://skillshunter.net/skills/discovered-34808a3fb3ae1cc18cefe15dfd5b7a4ef251b0c4d0bb3d67

**JSON URL:** https://skillshunter.net/api/public/v1/skills/discovered-34808a3fb3ae1cc18cefe15dfd5b7a4ef251b0c4d0bb3d67

**Markdown URL:** https://skillshunter.net/skills/discovered-34808a3fb3ae1cc18cefe15dfd5b7a4ef251b0c4d0bb3d67.md

**Instructions download URL:** https://skillshunter.net/skills/discovered-34808a3fb3ae1cc18cefe15dfd5b7a4ef251b0c4d0bb3d67/download

**Category:** Software & Development

**Source URL:** https://github.com/jueyi6/empstack/blob/74181e31d2f00313f8683ba157966efcabbe109e/skills/principle-separate-before-serializing-shared-state/SKILL.md

**Source commit:** 74181e31d2f00313f8683ba157966efcabbe109e

**Listing approved at:** 2026-12-02

**Created at:** 2026-11-30T08:56:29.000000Z

**Updated at:** 2026-12-02T09:15:14.000000Z

## Catalog information

The following descriptions are catalog information. Listing approval does not mean the skill has been tested or is safe for every environment.

### Editor's note

Before implementing shared state serialization, confirm whether actors require a single shared object or can operate independently. If independent, assign each actor its own file, key, or directory, and merge only during reads.

### When to use it

- Managing concurrent writes to shared files in distributed systems
- Avoiding race conditions in multi-threaded applications
- Designing state management in parallel processing pipelines

## Skill instructions

---
name: principle-separate-before-serializing-shared-state
description: When parallel actors share a write target, separate them first.
disable-model-invocation: true
---

# Separate Before Serializing Shared State

When concurrent actors might write the same file, branch, key, or object, first ask whether they need one shared object or are publishing independent facts. Default to giving each actor its own file, key, branch, or state directory, and merge only where the state is read. Two workers writing their own field into one `state.json` is still shared mutation.

Only when one shared write target is a real invariant, serialize access structurally (a lockfile, a single writer, sequential phases, compare-and-swap). Instructions are not concurrency control, and "we need a lock" is a smell to check first.

