This page follows the Apache Avro specification, both the 1.12.0 release documentation and the current text in the Avro repository, read 2026-11-12; they agree on everything below. The variable-length integers follow the Lucene 3.5 VInt that the specification links, read 2026-11-12. Binary Avro data has no field names or type information, so reading it needs the schema it was written with, which a container file carries in its header.
Schema types
| Type | Binary encoding |
|---|---|
null | Nothing. |
boolean | One byte, 0 or 1. |
int, long | Zig-zag, then variable length: 7 bits per byte, low bits first, high bit set when more follow. 0 → 00, −1 → 01, 1 → 02, −64 → 7F, 64 → 80 01. |
float, double | 4 or 8 bytes IEEE 754, little-endian. |
bytes, string | A long length, then the bytes (UTF-8 for strings). |
record | The fields in schema order, nothing between. Attributes: name, namespace, doc, aliases, fields (each name, type, doc, default, order, aliases). |
enum | An int: the index in symbols. Optional default symbol for readers. |
array | Blocks: a long count, then that many items; a count of 0 ends. A negative count means its absolute value, followed by the block’s size in bytes, so readers can skip it. |
map | Blocks as for arrays, each entry a string key and a value of type values. |
| union | Written in JSON as an array of types. An int giving the zero-based index of the branch, then the value. (The specification notes that C and C++ implementations treat the index as an int, though in theory it is a long.) |
fixed | Exactly size bytes. |
Logical types
logicalType | On | Meaning |
|---|---|---|
decimal | bytes, fixed | Two’s complement big-endian unscaled value, with precision and scale |
big-decimal | bytes | Decimal with its scale stored in the value: the bytes hold an Avro bytes value (two’s complement big-endian unscaled value) followed by the scale as an Avro int |
uuid | string, fixed(16) | A randomly generated universally unique identifier; both the string layout and the 16-byte fixed layout must conform to RFC 4122 |
date | int | Days since 1970-01-01 |
time-millis, time-micros | int, long | Time of day: milliseconds or microseconds after midnight |
timestamp-millis, -micros, -nanos | long | Instant: units since the Unix epoch, 1970-01-01 00:00:00 UTC |
local-timestamp-millis, -micros, -nanos | long | Timestamp in a local time zone, whichever is considered local: units from 1970-01-01 00:00:00 |
duration | fixed(12) | Three unsigned 4-byte little-endian numbers: months, days, milliseconds |
A reader that does not know a logical type uses the underlying type.
Object container file
| Part | Encoding |
|---|---|
| Magic | 4F 62 6A 01: Obj and 1. |
| Metadata | A map of bytes. avro.schema: the schema as JSON. avro.codec: the codec (absent means null). Keys starting avro. are reserved. |
| Sync marker | 16 random bytes. |
| Blocks | A long count of objects, a long size in bytes of the serialised objects after compression, the objects, then the 16-byte sync marker. |
| Codec | Block data |
|---|---|
null | Not compressed. Required of every implementation. |
deflate | Deflate as in RFC 1951, not the RFC 1950 zlib format, so no checksum. Required. |
bzip2 | bzip2. |
snappy | Snappy, followed by a 4-byte big-endian CRC-32 of the uncompressed data. |
xz | XZ. |
zstandard | Zstandard. |
Single-object encoding
For one value outside a container (for example a message): the marker
C3 01 (single-object format version 1), the 8-byte little-endian
CRC-64-AVRO (64-bit Rabin) fingerprint of the object’s schema, then the binary value.
Readers use the marker to tell an Avro payload apart before looking the schema up by
its fingerprint.
Container file schemas and codecs in the specification
From the Avro 1.12.0 specification, section “Object Container Files” (downloaded 2026-11-13). The specification gives the header and the data block as Avro schemas:
{"type": "record", "name": "org.apache.avro.file.Header",
"fields" : [
{"name": "magic", "type": {"type": "fixed", "name": "Magic", "size": 4}},
{"name": "meta", "type": {"type": "map", "values": "bytes"}},
{"name": "sync", "type": {"type": "fixed", "name": "Sync", "size": 16}}
]}
{"type": "record", "name": "org.apache.avro.file.DataBlock",
"fields" : [
{"name": "count", "type": "long"},
{"name": "data", "type": "bytes"},
{"name": "sync", "type": {"type": "fixed", "name": "Sync", "size": 16}}
]}
The block size long counts the serialised objects after any codec is applied. Each block
can be extracted or skipped without deserialising it, and block sizes, object counts and
sync markers allow corrupt blocks to be detected. Metadata keys starting avro.
are reserved; the two the specification currently uses are avro.schema
(required) and avro.codec. Implementations must support null and
deflate.
What the specification says about the optional codecs. This is all of it:
bzip2 “uses the bzip2 compression library”; snappy
“uses Google’s Snappy compression library” and each compressed block is
followed by the 4-byte big-endian CRC32 checksum of the uncompressed data in the block;
xz “uses the XZ compression library”; zstandard
“uses Facebook’s Zstandard compression library”. The specification gives
no parameters, frame details or checksum for these beyond the Snappy CRC; the codecs are
the formats of those libraries (see the compression pages
for bzip2, XZ and Zstandard).
Avro IDL (.avdl)
Not part of the .avro file format. An .avdl file is source text for a schema or a
protocol, a format of its own that no container file or single-object message contains; this page keeps its
summary only for the language that writes the schemas stored in .avro files. The file viewer does not read it.
From the Avro 1.12.0 “IDL Language” page (downloaded 2026-11-13). Avro IDL is a
higher-level language for writing Avro schemas and protocols; the idl tool of
avro-tools converts .avdl to .avsc (schema) or
.avpr (protocol), and a Maven plugin has an idl goal.
| Element | Syntax | Rule |
|---|---|---|
| File | one schema definition or one protocol definition | A file holds exactly one main schema or exactly one protocol. |
| Schema file | namespace ns; optional, then schema int; | schema T; names the main schema (any type, for example a named record defined in the file); namespace sets the default namespace for named schemas, and without it the null namespace applies. A file that uses schema is equivalent to an .avsc. May contain imports and named-schema definitions. |
| Protocol file | @namespace("ns") protocol Name { ... } | May contain imports, named schemas and RPC messages; protocol MyProtocol { } generates {"protocol": "MyProtocol", "types": [], "messages": {}}. |
| Imports | import idl "foo.avdl";, import protocol "foo.avpr";, import schema "foo.avsc"; | File names resolve relative to the importing IDL file. Importing into a schema file brings only the named types; into a protocol, messages come too. |
| Enum | enum Shapes { SQUARE, TRIANGLE, CIRCLE } = CIRCLE; | C or Java style. The optional = SYMBOL is the default used when a reader meets a writer symbol it does not know (not when the field is missing). Anonymous enums cannot be defined. |
| Fixed | fixed MD5(16); | A named fixed type of 16 bytes. |
| Record, error | record Employee { string name; boolean active = true; long salary; }; error Kaboom { ... } | Each field has a type, a name, optional property annotations and an optional default (JSON, interpreted as in the specification). error replaces record for errors. |
| Type references | primitive, logical, named schema, or complex | A named schema may be referenced by name once defined (or imported). Primitives: int, long, string, boolean, float, double, null, bytes. |
| Logical types | decimal(9,2) (decimal), date (date), time_ms (time-millis), timestamp_ms (timestamp-millis), local_timestamp_ms (local-timestamp-millis), uuid (uuid) | For any other logical type use the annotation: @logicalType("timestamp-micros") long finishTime;. |
| Array | array<t> | Nests: array<array<Foo>>. |
| Map | map<t> | Keys are always strings. |
| Union | union { null, string } | The JSON rules apply: no two members of the same type; a union field with a default must have a default of the first member's type. |
| Nullable shorthand | string? f = null; | A union of null and one type; null is first or last depending on the default (first with no default or a null default; with = "something" the other type goes first). |
| Message | int add(int foo, int bar = 0); | Like a method declaration; arguments may have defaults. void is an alias of the null type; void goKaboom() throws Kaboom; names declared errors (an error type defined or imported in the same protocol); void fireAndForget(string message) oneway; marks a one-way message. |
| Comments | // ..., /* ... */, /** ... */ | Java style; a /** comment becomes the doc string of the type or field that follows it. |
| Escaped identifiers | `error` | Backticks make a keyword usable as an identifier anywhere an identifier is expected. |
| Annotations | @order("ascending"|"descending"|"ignore"), @namespace("..."), @aliases([...]), @logicalType("..."), any other @name(value) | @order goes before the field name (string @order("ignore") f;); a field's type, except a type reference, may be preceded by annotations (@java-class("java.util.ArrayList") array<string> f;, also inside array<...> and with @java-key-class on a map); @namespace on a named schema overrides the namespace it would inherit from its container; @aliases on a type or on a field. All other annotations become properties of the protocol, message, schema or field; a property name is any identifier or series of identifiers separated by dots and/or dashes. |
The page's complete example is a schema file (namespace org.apache.avro.test; schema TestRecord; with enum Kind having default FOO, fixed MD5(16), and a record using @order, @aliases and the nullable shorthand) and a protocol file importing it with import idl "schema.avdl";, defining an error and messages hello, echo, add, echoBytes, error (throws TestError) and ping (oneway). The page states that more examples are in the Avro source tree under src/test/idl/input. It gives no formal grammar; the IDL page is the specification of the language, so the table above is complete relative to it. Editors it lists with support: a JetBrains plugin, Avroclipse for Eclipse, a Visual Studio Code extension, an Atom package and two Vim plugins.
Names, aliases and defaults
From the Avro 1.12.0 specification (read 2026-11-13).
- Full names. A name containing a dot is a full name and any
namespaceis ignored. A simple name with anamespacegivesnamespace.name. A simple name alone takes the namespace of the most tightly enclosing named schema or protocol (or none). References follow the same rule. Primitive names have no namespace and may not be defined in one; complex type names may be reused as type names, though a namespace is advised. A full name may be defined once and before its use in a depth-first, left-to-right reading (a protocol'stypescounts as before itsmessages). - Name syntax. The name part of a named type's full name, every record field name and every enum symbol must start with
[A-Za-z_]and then contain only[A-Za-z0-9_]. A namespace is a dot-separated sequence of such names, or the empty string for the null namespace, which cannot appear inside a dotted sequence; the grammar is<empty> | <name>[(<dot><name>)*]. Names, field names, enum symbols and full names are compared case-sensitively. Two different types with the same full name are an error. Field names and enum symbols are equal only within their own record or enum (no namespace), so the same name may be reused in another type, but defining two fields in one record or two symbols in one enum with the same name is an error (enum symbols must also match the name regular expression). - Union restrictions (JSON schema form). A union may not contain more than one schema of the same type, except for the named types record, fixed and enum (two array types or two map types are not allowed; two named types with different names are, because names permit efficient resolution when reading and writing unions). A union may not immediately contain another union. A union field's default value must match one element of the union.
- Aliases rewrite the writer's schema using the reader's: a writer type
Fooread by a typeBarthat has the aliasFoois read asBar; likewise a writer fieldxread as a fieldywith the aliasx. A type alias is either fully namespace-qualified or relative to the namespace of the name it is an alias for: a type nameda.bwith aliasescandx.yhas the fully qualified aliasesa.candx.y. Aliases are alternative names, subject to the same uniqueness rules; they should be valid names but any string is accepted, so old illegal names can be corrected. - Defaults. A field's
defaultis used only when reading data that lacks the field; it does not make the field optional when writing, and Avro writes a field even if it equals its default. Defaults for a union field correspond to the first schema that matches in the union (the 1.12.0 wording; the IDL page says the default must be of the first union type, which is the stricter form). An invalid default is only used to fill in missing data when reading, and creates invalid values in those cases; the fix is to correct the default values. JSON forms: null asnull; boolean; int and long as a JSON integer; float and double as a number; bytes and fixed as a string whose code points 0–255 are the byte values ("ÿ"); string; enum as a string symbol; array as an array; map and record as an object. An enum may have adefaultsymbol, used in resolution when the writer's symbol is missing from the reader's enum. - Logical types are written with their underlying type; unknown or invalid logical types are ignored when reading, using the underlying type.
decimalannotates bytes or fixed: the two's-complement unscaled integer, big-endian, with requiredprecisionand optionalscale(default 0, at most the precision, and zero or positive).precisionmust be a positive integer greater than zero. If the underlying type isfixed, the precision is limited by its size: an array of length n can store at most floor(log10(28n-1 - 1)) base-10 digits of precision. For schema resolution, two decimal logical types match if their scales and precisions both match.
Schema resolution
A feature of the program that reads, not content of a file. A file holds only its writer schema;
the reader schema belongs to the application and is not stored anywhere in the file, so a viewer that
shows what the file holds has nothing to resolve against. The rules are listed here because they say how the
writer schema, default values, aliases and enum defaults in a file are meant to be used.
A reader may read data written with a different schema. The two schemas match if: both are arrays with matching item types; both maps with matching value types; both enums with the same unqualified name; both fixed with the same size and unqualified name; both records with the same unqualified name; either is a union; or both have the same primitive type. A writer type may also be promoted: int to long, float or double; long to float or double; float to double; string to bytes; bytes to string. If they do not match it is an error.
- Records: fields are matched by name, in any order, and resolved recursively. A writer field the reader does not have is skipped. A reader field the writer lacks takes the reader's default, or, with no default, is an error.
- Enums: a writer symbol missing from the reader's enum becomes the reader's default if it has one, otherwise an error.
- Arrays and maps: the item or value schemas are resolved recursively.
- Unions: both unions: the first reader branch that matches the writer's chosen branch is used; none is an error. Reader only a union: the first matching reader branch. Writer only a union: the reader's schema must match the branch the writer chose.
docis ignored in resolution and may be dropped when storing a schema. Because the binary encoding has no field names, reading with a schema that is not the writer's works only if the serialised primitives agree value by value; using schemas with identical parsing canonical form is safer.
Parsing canonical form and fingerprints
Two schemas whose parsing canonical forms are textually equal are the same for every
reader. The transformations: primitives to their simple form (int,
not {"type":"int"}); full names replace short names and
the now-redundant namespace attributes are dropped; strip everything
but type, name, fields, symbols,
items, values, size (doc,
aliases and the rest go); order the members of each JSON
object as name, type, fields, symbols, items, values, size;
strings: escapes such as \uXXXX replaced by their UTF-8
characters; integers: no quotes or leading zeros (the
size of a fixed); whitespace outside strings removed.
Fingerprints of the canonical form, recommended: SHA-256 (256 bits); MD5 (128 bits, for tens of millions of schemas); and the 64-bit CRC-64-AVRO (Rabin):
EMPTY = 0xc15d213aa4d7a795
FP_TABLE[i] for i in 0..255: fp = i; repeat 8 times: fp = (fp >>> 1) ^ (EMPTY & -(fp & 1)); store fp
fingerprint64(buf): fp = EMPTY; for each byte b: fp = (fp >>> 8) ^ FP_TABLE[(fp ^ b) & 0xff]
The initial value is EMPTY instead of zero so that, as the specification explains,
a leading one bit is prepended and leading zero bits are not ignored. A 64-bit
fingerprint is adequate for caches up to about a million schemas (collision chance
3×10−8); they give no security guarantee. The single-object
encoding (C3 01, then the 8-byte little-endian CRC-64-AVRO fingerprint,
then the object) uses it.
JSON encoding and sort order
- JSON encoding is the same as for field defaults, except for unions:
nullis JSONnull; any other branch is an object with one pair whose name is the branch's type name (the user name for record, fixed and enum; the type name otherwise) and whose value is the encoded value. For["null","string","Foo"]:null,{"string": "a"},{"Foo": {...}}. The schema is still needed: JSON does not tell int from long, float from double, records from maps, or enums from strings. - Sort order (items with identical schemas only, depth-first, first difference decides): null always equal; false before true; numbers by value; bytes and fixed lexicographically by unsigned bytes; strings by Unicode code point (the same as UTF-8 bytes); arrays lexicographically by element; enums by symbol position in the schema; unions by branch index then within the branch; records lexicographically by field, each field's
orderbeingascending(default),descending(reversed) orignore; maps cannot be compared, except inside an"order":"ignore"field.
Protocols and the RPC wire format
Not part of the .avro file format. A protocol (.avpr, JSON) and the RPC messages
that use it are separate formats from the object container file and the single-object encoding; no
.avro file holds them. They are summarised here only because they share the schema language and the
binary encoding. The file viewer does not read them.
- Declaration. A JSON object:
protocol(name, required),namespace,doc,types(named types; anerroris a record with the typeerror; no forward references), andmessages(an object; names unique). A message hasdoc,request(a list of named, typed parameters like record fields, resolved like record fields between caller and responder),response, an optionalerrorsunion, andone-way(allowed only when the response is"null"and there are no errors). The effective error union has"string"prepended (for undeclared system errors): declared["AccessError"]is["string","AccessError"]; with none declared it is["string"]. Errors are written with the effective union. - Transport. A message is an opaque byte sequence to the transport, which sends requests and receives responses, statelessly or statefully. Over HTTP each exchange is one request and response (all messages of a protocol share one URL, status 200 for normal and error responses, content type
avro/binary, POST); it is a stateless transport. - Framing. A message is a series of buffers, each a 4-byte big-endian length then that many bytes, ended by a zero-length buffer. Framing is invisible to the request and response formats.
- Handshake. Records
org.apache.avro.ipc.HandshakeRequest(clientHashfixed MD5 of 16,clientProtocolnull or string,serverHashMD5,metanull or map of bytes) andHandshakeResponse(matchenumBOTH,CLIENT,NONE;serverProtocolnull or string;serverHashnull or MD5;meta). The hashes are 128-bit MD5 hashes of the JSON protocol text. A client first sends only its own hash and its guess of the server's.BOTH: the hashes were right and the response follows.CLIENT: the server knows the client's protocol but the server hash was wrong; the reply carries the server protocol and hash, which the client must use and cache.NONE: the server has not seen the client's protocol, so the client resubmits withclientProtocolfilled in and expectsBOTH. With a stateless transport every request and response has a handshake; with a stateful one only until a successful handshake response.metais reserved. - Call. Request: metadata (a map of bytes), the message name (a string), then the parameters per the request declaration. An empty message name asks the server to ignore the parameters and return an empty response (a ping or a bare handshake). Response: metadata, a boolean error flag, then the response (flag false) or the error per the effective union (flag true). A one-way message on a stateful connection after a successful handshake gets no response data.