Serialization Best Practices
Account bytes are your database schema. These practices keep layouts auditable, migration-friendly, and resistant to type confusion.
Search across all documentation pages
Account bytes are your database schema. These practices keep layouts auditable, migration-friendly, and resistant to type confusion.
LEN or SPACE constants; assert at runtime on access. Prevents partial read/write bugs.space attributes with native constants. Single source of truth.Borsh unless profiled need.
8 bytes Anchor style common.
Rare - prefer pubkey keys.
Review generated size.
No migrations possible - plan space.
Not native on-chain.
Off-chain only.
In repo docs.
Client decode alignment.
From unbounded Vec.
Rent rules via SDK.
Disc + LEN + migration.
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 16, 2026