Part 5 · Apache Iceberg spec · Chapter 21
The REST catalog protocol
The Iceberg REST catalog spec: configuration, loading a table, credential vending, commits as requirements plus updates, what the server does with them, failures, idempotency keys, multi-table transactions and server-side scan planning.
After this chapter you should be able to:
- Read a commit request (requirements plus updates) and predict whether the server accepts it.
- Explain what the server does on a lost swap, and what a client may assume after a 409 or a 5xx.
- Explain credential vending and remote signing, and why they matter for governance.
Chapter 17 ended at the catalog: an Iceberg commit is a compare-and-swap of one pointer, from the old metadata file to the new one, and the catalog is whatever holds that pointer. Hive, Glue, JDBC and Nessie each do the swap their own way, and each needs a client library per engine. The REST catalog spec replaces them with one HTTP API, defined as an OpenAPI document, so any engine with a REST client can use any server that implements it.[openapi]
The API does more than swap a pointer. The client sends the change, not a new metadata file, and the server writes the metadata. That moves the last step of the commit to the server, and it gives the server a place to enforce access, hand out storage credentials and plan scans. This chapter follows the spec and the Java client and reference server code.
Links point to apache/iceberg at 9d2bf51.
- GET /v1/config?warehouse=wh. Returns defaults, overrides and (optionally) the endpoints the server supports. The client builds its configuration as defaults, then its own properties, then overrides. getConfig ↗
- GET …/tables/events X-Iceberg-Access-Delegation: vended-credentials. The header says which ways of getting storage access the client supports. The server may pick any or none of them. data-access ↗
- 200 {metadata-location, metadata, config, storage-credentials}. The full table metadata, table-level config (for example a FileIO), and short-lived credentials per location prefix. The client picks the credential with the longest matching prefix. LoadTableResult ↗
- read manifests; write data files, manifests, manifest list. Everything below the metadata file is still written by the client, with the vended credentials. The catalog never sees data.
- POST …/tables/events {requirements, updates}. The updates describe the change (add-snapshot, set-snapshot-ref main). The requirements are assertions about the metadata the client started from, derived by UpdateRequirements.forUpdateTable. forUpdateTable ↗
- validate, apply, write 00005-….metadata.json, swap. The server checks every requirement against its current metadata, applies the updates, writes the new metadata file and swaps its pointer. A lost swap is retried inside the server, re-checking the requirements. CatalogHandlers.commit ↗
- 200 {metadata-location, metadata} or 409. On 409 the client refreshes, re-applies its operation (with the validations of chapter 17) and sends a new request. 500, 502, 503 and 504 mean the commit state is unknown. updateTable ↗
Configuration
A client starts with GET /v1/config, optionally with ?warehouse=. The response has defaults and overrides. The client’s final configuration is built in three layers: defaults, then its own properties, then overrides. A server uses defaults for things the client may change (a client pool size) and overrides for things it owns (the warehouse location). The response can also list the endpoints the server supports; if it doesn’t, the client assumes a fixed default set, which includes table commits and multi-table transactions but not views or scan planning.[openapi]
Every other path starts with /v1/{prefix}/, where the prefix comes from the config. A multi-part namespace is one path segment, with parts joined by the namespace separator. The default separator is the unit separator byte 0x1F, so accounting.tax becomes accounting%1Ftax. A server that advertises another separator must still accept 0x1F, for older clients.[openapi]
Q1. The server returns defaults {clients: 4} and overrides {warehouse: s3://bucket/wh/}. The client sets clients=8 and warehouse=s3://mine/. What does it end up with?
Q2. How is the namespace accounting.tax written in a REST path by default?
Loading a table
GET /v1/{prefix}/namespaces/{namespace}/tables/{table} returns a LoadTableResult:[openapi]
{
"metadata-location": "s3://wh/db/events/metadata/00004-….metadata.json",
"metadata": { "format-version": 2, "table-uuid": "9c12d441-…", "current-snapshot-id": 101, "…": "…" },
"config": { "io-impl": "org.apache.iceberg.aws.s3.S3FileIO" },
"storage-credentials": [
{ "prefix": "s3://wh/db/events/", "config": { "s3.access-key-id": "…", "s3.secret-access-key": "…", "s3.session-token": "…" } }
]
}
metadata is the full table metadata, the same JSON as the metadata file. metadata-location is where that file is; it is null for a table staged in a create transaction. config is table-level configuration that overrides the catalog’s, for example a different FileIO. With snapshots=refs the server returns only snapshots that a branch or tag points at; the default is all. A client that sends the ETag from an earlier response in If-None-Match can get a 304 Not Modified instead of the whole document.[openapi]
From here the client works as it would with any catalog. It plans with the manifest list and manifests, reads data files, and for a write produces data files, manifests and a manifest list, all in object storage. The catalog never handles data.
Credentials
The REST spec answers a question the file-based catalogs leave to the engine: how does the client get permission to read and write the table’s files? The client sends X-Iceberg-Access-Delegation with the mechanisms it supports, vended-credentials, remote-signing or none, and “the server may choose to supply access via any or none of the requested mechanisms”.[openapi]
- Vended credentials. The response’s
storage-credentialslists credentials per location prefix. “Clients should choose the most specific prefix (by selecting the longest prefix)”, and must look there before looking for credentials inconfig.[openapi] In AWS terms these are an access key, a secret and a session token: short-lived and scoped to the table’s location.GET …/tables/{table}/credentialsrefreshes them.[openapi] - Remote signing. The client never gets storage credentials. It sends each S3 request to the server’s signer (
POST …/tables/{table}/sign), which returns a signed request if the call is allowed.[openapi]
Either way, storage access follows the catalog’s authorization of this user on this table. A user who can’t load the table gets no credentials for its files, and no long-lived bucket keys need to be handed to engines. This is the hook a governance layer such as Unity Catalog (chapters 23 and 24) needs.
The catalog API itself is protected by a bearer token. The spec’s own /v1/oauth/tokens endpoint is “DEPRECATED for REMOVAL”, deprecated since Iceberg Java 1.6.0 and to be removed in 2.0, and clients are told to set oauth2-server-uri to a real OAuth server instead.[openapi]
Q1. What does vended-credentials in X-Iceberg-Access-Delegation ask for?
Q2. What is the status of the /v1/oauth/tokens endpoint at the pinned commit?
Commits
A commit is POST …/tables/{table} with a CommitTableRequest: a list of requirements and a list of updates.[openapi] Here is an append to main, from a client that loaded the table when main was at snapshot 101:
{
"requirements": [
{ "type": "assert-table-uuid", "uuid": "9c12d441-…" },
{ "type": "assert-ref-snapshot-id", "ref": "main", "snapshot-id": 101 }
],
"updates": [
{ "action": "add-snapshot", "snapshot": {
"snapshot-id": 200, "parent-snapshot-id": 101, "sequence-number": 2,
"manifest-list": "s3://wh/db/events/metadata/snap-200-….avro",
"summary": { "operation": "append" } } },
{ "action": "set-snapshot-ref", "ref-name": "main", "type": "branch", "snapshot-id": 200 }
]
}
Updates are changes to table metadata: add-snapshot, set-snapshot-ref, add-schema, set-current-schema, add-spec, set-default-spec, add-sort-order, set-default-sort-order, set-properties, remove-snapshots, upgrade-format-version and others. An id of -1 in set-current-schema or set-default-spec means the one added earlier in the same request.[openapi] The client never sends a metadata file. In the Java client, RESTTableOperations.commit takes the new metadata the operation built, sends its changes() as updates, and replaces its state with the metadata in the response.[src]
- Client sends a proposal Assert the table UUID and that main is at snapshot 101.
- Server checks requirements Evaluate the assertions against current metadata.
- Server applies updates Add snapshot 200 and move main to it if the requirements hold.
Q1. With a REST catalog, who writes the new metadata.json for a commit?
Requirements
Requirements are assertions about the table that the server checks before applying the updates. There are eight:[openapi]
| Requirement | Holds when |
|---|---|
assert-create | the table does not exist |
assert-table-uuid | the table’s UUID is uuid |
assert-ref-snapshot-id | ref ref points at snapshot-id, or does not exist if snapshot-id is null |
assert-last-assigned-field-id | last-column-id is unchanged |
assert-current-schema-id | the current schema is unchanged |
assert-last-assigned-partition-id | last-partition-id is unchanged |
assert-default-spec-id | the default spec is unchanged |
assert-default-sort-order-id | the default sort order is unchanged |
The spec doesn’t say which requirements a client must send. The Java client derives them from its updates in UpdateRequirements.forUpdateTable, against the metadata it started from:[src][src]
builder.require(new UpdateRequirement.AssertTableUUID(base.uuid()));
metadataUpdates.forEach(builder::update);
private void update(MetadataUpdate.SetSnapshotRef setRef) {
boolean added = changedRefs.add(name); // once per ref
if (added && base != null && !isReplace) {
SnapshotRef baseRef = base.ref(name);
require(new AssertRefSnapshotID(name, baseRef != null ? baseRef.snapshotId() : null));
}
}
private void update(MetadataUpdate.AddSchema unused) {
if (!addedSchema) { require(new AssertLastAssignedFieldId(base.lastColumnId())); ... }
}
// SetCurrentSchema -> AssertCurrentSchemaID, AddPartitionSpec -> AssertLastAssignedPartitionId,
// SetDefaultPartitionSpec -> AssertDefaultSpecID, SetDefaultSortOrder -> AssertDefaultSortOrderID
// RemoveSchemas / RemovePartitionSpecs also pin every branch other than main
So each kind of change asserts only what it depends on. An append asserts that main hasn’t moved. A schema change asserts last-column-id, so two concurrent ADD COLUMNs can’t both assign field id 4 (chapter 19). A property change asserts only the UUID, so it never conflicts with an append. add-snapshot asserts nothing by itself: the snapshot’s position in history is guarded by the ref requirement.
This is the same optimistic scheme as chapter 17, with one level moved. The client-side checks of MergingSnapshotProducer (added files, deleted files, delete files since the starting snapshot) still run in the client before it sends anything. The requirements only protect the metadata swap.
Q1. A Java client appends to main, starting from snapshot 101. Which requirements does it send?
Q2. Which requirements does an ADD COLUMN commit (add-schema, then set-current-schema -1) carry? (select all that apply)
Q3. Two clients load v1. One sets a table property, the other appends. Both send their requests. What happens?
On the server
The spec defines the contract; the Java reference implementation shows one way to meet it. CatalogHandlers.commit wraps any Catalog whose TableOperations can swap metadata atomically:[src]
Tasks.foreach(ops)
.retry(COMMIT_NUM_RETRIES_DEFAULT) // 4
.exponentialBackoff(100, 60_000, 30 * 60_000, 2.0)
.onlyRetryOn(CommitFailedException.class)
.run(taskOps -> {
TableMetadata base = isRetry.get() ? taskOps.refresh() : taskOps.current();
isRetry.set(true);
try {
request.requirements().forEach(requirement -> requirement.validate(base));
} catch (CommitFailedException e) {
throw new ValidationFailureException(e); // no retry: 409 to the client
}
TableMetadata.Builder metadataBuilder = TableMetadata.buildFrom(base);
try {
request.updates().forEach(update -> update.applyTo(metadataBuilder));
} catch (RetryableValidationException e) {
throw new ValidationFailureException( // stale values in the request: 409
new CommitFailedException(e, "Validation failed, please retry: %s", e.getMessage()));
}
TableMetadata updated = metadataBuilder.build();
if (updated.changes().isEmpty()) return; // nothing to commit
taskOps.commit(base, updated); // writes the metadata file and swaps
});
Two loops are at work. The server’s loop handles a lost swap: another request committed between this request’s read of the metadata and its swap. The server refreshes, checks the requirements again on the new metadata, and if they still hold, applies the same updates to it. A property change that lands in that window doesn’t fail an append. A failed requirement ends the loop at once with a 409, because retrying the same request can’t fix it.
The client’s loop handles the 409. SnapshotProducer.commit refreshes, re-runs the operation against the new base (including chapter 17’s conflict validation), writes a new manifest list with the new sequence number, and sends a new request. The server catches one more kind of stale request: add-snapshot with a sequence number not greater than the table’s last-sequence-number raises a RetryableValidationException, which becomes a 409 with “Validation failed, please retry”.[src] The same check exists for first-row-id in v3. Unknown update or requirement types must be rejected with 400.[openapi]
Q1. The server validated a request against v4, but another commit wins the swap and the table is now v5. What does CatalogHandlers.commit do?
Q2. A request contains an update type the server does not recognise. What must the server do?
Failures and retries
The spec gives the commit endpoint these outcomes: 200 with the new metadata-location and metadata; 409 when “one or more requirements failed. The client may retry.”; and 500, 502 and 504 when “the commit state is unknown”.[openapi] The Java error handler maps 409 to CommitFailedException and 500, 502, 503 and 504 to CommitStateUnknownException.[src] Chapter 17 explained why an unknown state is dangerous: retrying might commit twice, and cleaning up the written files might delete files the table now references.
The Java client handles one unknown case by itself. If the request only added one snapshot and at most moved main to it, it refreshes the table and checks whether that snapshot id exists. If it does, the commit happened.[src] For other requests, such as a schema change, there is no such check.
The general fix is the Idempotency-Key header, a UUIDv7 the client sends with a mutation. If the server has finalized a request with that key, it returns the stored response without running the operation again. 2xx and deterministic 4xx responses are finalized and replayed; 5xx are not.[openapi] A server that supports keys says so with idempotency-key-lifetime in /v1/config, and only then does the Java client send them.[src] With a key, a client that timed out can resend the same request and get the original 200, instead of a 409 caused by its own earlier commit.
Q1. A commit returns 504. What may the client assume?
Q2. After an unknown-state error, when does the Java client resolve the outcome by itself?
Q3. A client resends a commit with the same Idempotency-Key after a timeout, and the first attempt had succeeded. What does the server return?
Multi-table transactions
POST /v1/{prefix}/transactions/commit takes a list of CommitTableRequests, each with a table identifier, and commits them “in an atomic operation”: every table’s requirements must hold and every update is applied, or nothing is.[openapi] A catalog that keeps one pointer per table in a metastore or a file can’t offer this. A REST server backed by a database can, which is one reason the REST protocol is where newer catalog features appear.
Q1. What does POST /v1/{prefix}/transactions/commit add over the single-table commit?
Server-side scan planning
The last step a client does itself is planning: reading manifests and choosing files. POST …/tables/{table}/plan moves that to the server. A request names a snapshot (or a start and end snapshot for an incremental scan), a filter and the columns. The response is either completed, with file scan tasks and plan tasks, or submitted with a plan-id to poll; plan tasks are fetched with POST …/tables/{table}/tasks.[openapi] A table’s config can include scan-planning-mode: client means the client must plan, server means it must use this endpoint and should fail fast if it can’t.[openapi] A client that doesn’t read manifests doesn’t need to understand them, and the server decides which files a scan returns.
Q1. A loadTable response has scan-planning-mode = server. What must the client do?
Try it
The lab starts with a table at metadata v1, with main at snapshot 101. Pick an operation to see the request the Java client would build. Then:
- Send an append. It commits as v2.
- Without refreshing, send another append from the stale base.
assert-ref-snapshot-idfails with the Java message. Click “Refresh and rebuild” and send again. - Let another writer “set a property” “while the server commits mine”. The first swap fails, the server retries, and the append still commits.
- Pick ADD COLUMN, let another writer add a column first, and send.
assert-last-assigned-field-idfails. - Tick “lose the response”. An append is reconciled by the client; an ADD COLUMN is not. Tick “Idempotency-Key” and resend the same request to see the stored response replayed.
Request
POST /v1/{prefix}/namespaces/db/tables/events
Content-Type: application/json
{
"requirements": [
{
"type": "assert-table-uuid",
"uuid": "9c12d441-03fe-4693-9a96-a0705ddf69c1"
},
{
"type": "assert-ref-snapshot-id",
"ref": "main",
"snapshot-id": 101
}
],
"updates": [
{
"action": "add-snapshot",
"snapshot": {
"snapshot-id": 200,
"parent-snapshot-id": 101,
"sequence-number": 2,
"summary": {
"operation": "append"
}
}
},
{
"action": "set-snapshot-ref",
"ref-name": "main",
"type": "branch",
"snapshot-id": 200
}
]
}Pick an operation, optionally let another writer in, and send. After a 409, refresh and rebuild: that is what the client's retry loop does.
updateTable ↗ · UpdateRequirements ↗ · CatalogHandlers.commit ↗
Comparison with Delta
The Delta protocol has no catalog API of its own; the log in object storage is the table, and chapter 14 showed catalog-managed tables, where commits go through a catalog that orders them. Iceberg’s REST spec covers more: loading, credentials, transactions and planning, as well as commits. The commit model differs too. A Delta client writes the commit JSON itself and the catalog only orders it, with conflict detection by the client after a failed write. An Iceberg REST client sends updates, and the server writes the metadata after checking the requirements.
Concepts in this chapter
Explained here
Primary sources
Review this chapter
This chapter has 15 quiz questions.