Tidemark

For application teams

This page is for the team that owns an application on a Kafka cluster Tidemark watches. It says what a restore gives back, what it cannot give back, and what your team must have done by the time the operators start one. The operators' side of the restore is in During the disaster and After the disaster.

In short: your application comes back at a consistent point shortly before the failure, with its inputs, outputs, offsets and changelogs all from the same instant. It then processes some records a second time, and whatever it wrote outside Kafka in the last moments before the failure, it writes again. Build for that, and a restore is a restart.

What a restore gives back

A restore rebuilds the cluster as it stood at a cut: one offset per partition, taken by Tidemark every few seconds while the cluster ran, and checked to hold no effect without its cause. It does not rebuild the cluster as it stood when it failed.

Everything written between the cut and the failure is not in the restore. That stretch is the gap, and its length is the recovery point (RPO): the age of the newest cut the backup fully covers. It depends on how often Tidemark takes a cut and how quickly the backup tool closes its segments, and is normally seconds. The operators see it on Tidemark’s home page; ask them what it is on your cluster.

Whether the gap hurts depends on where its records came from:

Records came from What happens to the gap

Another Kafka topic, through your application

Nothing is lost. Your group resumes before the cut and produces those records again.

A database, through a Connect source connector

The connector’s offsets come back at the cut, so it reads the gap from the database again.

A device or system that buffers and resends

It resends, as long as its buffer is longer than the gap. Have it resend from the newest record Kafka still has, not by time.

An application that writes straight into Kafka, and nowhere else

Lost. Nothing outside Kafka ever had those records. The cut names the first missing offset on every partition, so you know exactly what is gone.

The same patterns on a running example: what each costs with no backup, with the backup alone, and with Tidemark, and what stays your team’s job either way.

At-least-once, even for exactly-once applications

After a restore every application processes with at-least-once semantics. That includes Kafka Streams with processing.guarantee=exactly_once_v2 and any other transactional producer. Two things cause it, and neither is a fault.

Group offsets are read before the partitions. Tidemark reads where every consumer group stands, then where every partition ends. A group can only have committed what it had already read, so its offset is at or before the cut. After the restore it resumes there and reprocesses whatever its last commit had not covered yet. Too early is the safe side: too late would skip records for good.

Open transactions are rolled back. The cut sits on each partition’s last stable offset, so a transaction still open at the cut is not in it: neither its records nor the offset commit it carried. Your application does that work again after the restore. Where the cut falls between the commit markers of one transaction on different partitions, Tidemark marks the cut as not atomic, and the restore takes the newest cut that is.

Exactly-once does not reach across the restore itself either. Your producers get a new producer id on the restored cluster, so the broker cannot recognise a record sent before the failure when it arrives again.

Tolerating duplicates

Inside Kafka, a duplicate is a record your consumers see twice. Downstream consumers should treat a record they have already applied as a no-op, which most do when they keep their state per key.

Outside Kafka it matters more. A database, a payment system or a mail server survived the failure. It already holds the effects of the gap, and after the restore your application produces them a second time. No restore can roll such a system back, because it never knew it was part of one.

The protection is in the sink:

  • Upsert on a business key. Write payment-orders into the database by the payment order’s id, not with a blind insert. The second write of the same order changes nothing.

  • Never key on partition and offset. The restored cluster numbers every partition from 0 again. An offset-based key makes every replayed record look new.

  • Guard against an older version overwriting a newer one, for example with a version column.

  • Where an effect cannot be repeated (adding to a balance, sending a mail, executing a payment), remember the id of every record applied and skip a repeat. Without ids, recompute the result from the source instead of patching it.

Tidemark does not make a sink idempotent, and it does not need to know which sinks you have. This is the one protection every application that writes outside Kafka has to build itself.

Kafka Streams

Local state is not restored

A Streams application keeps its state stores on local disk, usually in RocksDB. That disk is not part of the cut, and where it survived, it holds updates from after the cut. Streams does not reliably notice: it compares offsets only, and stale keys stay in the store across later restarts.

Before a restored Streams application starts, delete its local state on every instance, standbys included:

  • empty the directory state.dir points to, or

  • call KafkaStreams#cleanUp() before start().

var streams = new KafkaStreams(topology, props);
// afterRestore: a flag set on the day,
// not on every start
if (afterRestore) {
  streams.cleanUp();
}
streams.start();

Streams then rebuilds every store from its changelog topic. Cleaning up on every start works too, but makes every routine restart rebuild all stores.

Changelog and internal topics are restored

Changelog, repartition and foreign-key subscription topics are restored with the rest, at the same cut as your inputs and your group. That is why a restored aggregation continues exactly, with its open windows, and needs no rewind.

Two rules follow:

  • Keep them in the backup. A new application or a changed topology creates new internal topics; tell the operators when you deploy one, so they can check that the backup covers them.

  • Do not run the application reset tool after a restore. It deletes the internal topics, and with them the state that came back consistent.

read_uncommitted consumers

isolation.level=read_uncommitted is the Java client’s default. On a topic written with transactions, such a consumer reads records of transactions that have not committed yet. The cut leaves those records out, because they were not decided when it was taken.

So the consumer’s group stands beyond the cut, and whatever it produced from those records is an effect whose cause the restore does not contain. No cut and no repair puts that right. The restore reports such a group and leaves it to a human, who decides with your team whether it starts fresh.

The fix is yours alone: set isolation.level=read_committed on every consumer of a transactional topic. The same holds for kafka-consumer-groups.sh --reset-offsets: never move a group forward past what is committed.

Compacted topics

The backup runs continuously, so it holds versions of a compacted topic that the live topic has already cleaned away, and the restore brings them back. Compaction runs again on the new cluster.

What the restore cannot bring back is history nobody kept. A compacted table such as customers keeps only the newest version of each key. If your application joins events with it and you recompute the join after a restore, every event is joined with today’s customer record, not with the one that applied when it happened.

  • Write the master data’s version into the joined record, so a wrong join can be seen at all.

  • If the joined result matters, keep it in a topic and back it up, instead of recomputing it.

Kafka Connect

A source connector keeps its positions in the Connect offsets topic. That topic is in the cut like any other, so after a restore the connector resumes right behind the restored data and reads the gap from its source again.

  • Keep the offsets topic in the backup. Without it the connector starts over and sends the whole history again.

  • Use exactly-once source support where the connector has it (exactly.once.source.support=enabled on the workers). Offsets and records are then written in one transaction, and the cut cannot separate them.

  • The source has to hold what the connector reads again: the database log or the upstream topic’s retention must reach back to the cut.

A sink connector is a consumer group like any application, and its target is a system outside Kafka. Everything in Tolerating duplicates applies: an upsert mode keyed on the record, never a plain insert.

Being released

On the day, your application stays stopped until the operators release it. Do not start it earlier, not even to check that it connects.

The restore fills the new cluster topic by topic and sets every consumer group while the group has no members; Kafka refuses to set a group’s offsets while a consumer is in it. An application that connects too early commits offsets of its own, reads a half-restored topic, or writes into one still being filled. Any of these breaks the consistency the cut was taken for.

That is why your application gets its ACLs only with its release. Until then it cannot reach the data, even by accident. It reaches the new cluster with the same principal it had before, so the ACLs recorded at the cut fit it.

Each application moves through the same states, independently of the others:

State Until

waiting for restore

every topic it may read or write is back

waiting for consumer group

every group it uses stands at its translated offsets, or a decision was made for it

waiting for its ACLs

its ACLs are on the new cluster

ready

your team starts it

running

—

A group whose next record is no longer there (below the log start), or that stood beyond the cut, is not set automatically. The operators decide with you: read everything again from the earliest record, skip to the latest, leave it to auto.offset.reset, or start fresh. There is no right answer, only a deliberate one. Know before the day which one your application can live with.

On the day

  1. Be reachable. The operators release applications one at a time and need a contact for each.

  2. Keep the application stopped, on every instance and in every deployment pointed at the cluster.

  3. Agree with the operators on any group they cannot set.

  4. When told your application is ready: delete its Kafka Streams state, then start it.

  5. Tell the operators it is running. They record it.

  6. Watch your sinks and downstream systems for duplicates from the gap, and for records that never come back because they existed only in Kafka.

After the restore

Ask the operators for the time of the cut and of your application’s release. Between the cut and the failure lies the stretch that every system outside Kafka has now seen twice, or once and never again.

  • Reconcile the systems your application writes to for that stretch, where their sinks are not idempotent.

  • For topics that only Kafka held, everything from the cut’s offset on is gone. Decide with the business whether any of it has to be recreated by hand.

What the operators close afterwards is in After the disaster.

Before a disaster: your checklist

  • ❏ Every consumer of a transactional topic uses isolation.level=read_committed.

  • ❏ Your application produces an effect only from a record it consumed, never two writes for one event with nothing read in between.

  • ❏ No group is ever moved forward past what is committed, by hand or by --reset-offsets.

  • ❏ Your application tolerates processing a record twice, exactly-once or not.

  • ❏ Every sink outside Kafka upserts on a business key, never on partition and offset; effects that cannot be repeated are guarded by an id.

  • ❏ The topics you read and write are in the backup and not on the operators' exclude list. An excluded topic comes back empty, and your group starts there at its auto.offset.reset.

  • ❏ Your consumer groups stay alive. A group idle for longer than the broker’s offsets retention has no offsets at the cut and starts at its auto.offset.reset.

  • ❏ Kafka Streams: you know how to delete local state on every instance, and the operators hear from you when your topology adds internal topics.

  • ❏ Kafka Connect: the offsets topic is backed up, and the source keeps enough history to resend the gap.

  • ❏ You know, per group, what it should do if its next records are gone: earliest, latest or start fresh.

  • ❏ The operators know whom to call in your team on the day.

What your team does not have to do: declare a restore scope, rewind anything after the restore, or use particular producer acks. The cut covers the whole cluster, your groups resume where their outputs end, and a record counts only once it is replicated, whatever the producer asked for.