Kappa architecture
medium 27 minKappa architecture uses one stream job and one log that keeps its events.
See it run
One log, one stream job. When the logic changes, a second job reads the same log from the start into a new table.
Operations
The normal day
Events go into the log, the job reads them in order and updates a table.
Step 1 of 4
Four events in the log
log
E1 · E2 · E3 · E4
E1 to E4 are appended. The job has handled three and is reading the fourth.
Step 1: Four events in the log
log.append(event) # the source of truthfor offset, e in log.read(after=saved): table[e.kind] += 1 # one logic saved = offset # stored with the table- Takes
- Seconds
- Needs
- Log and one table
The table is only a copy. The log can build it again.
In the real world
The same kappa architecture doing real jobs. Pick one and step through it.
A bug from 12 days ago, and a topic that keeps 7.
Step 1 of 4
A new topic
The team left the retention at Kafka's default: 7 days.
Step 1: A new topic
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Clearing the table before the replay
criticalUsers see zeros for hours, and the live job writes into the same table.
Wrongtable.clear()replay(into=table)Rightreplay(into=new_table) # then switchReusing the consumer group
criticalThe setting auto.offset.reset is used only when the group has no valid position. With an old position nothing is replayed.
Wronggroup="main"; reset="earliest"Rightgroup="main-v2"; reset="earliest"Sending emails again
criticalA replay repeats every side effect of the job.
Wrongon_order(e): send_email(e)Righton_order(e): emit(e)# one separate sender, ids rememberedA random key
majorWith the event id as key, events of one user land in different partitions and lose their order.
Wrongappend(key=event.id)Rightappend(key=event.user)
Interview tips
How to explain it
- One log, one stream job, views built from it.
- Reprocess means: read again from the start.
- No batch layer.
Five steps of a replay
- Deploy version 2.
- Start from the first offset, new group.
- Rebuild into a new table.
- Catch up and compare.
- Switch, then remove the old one.
K-A-P-P-A
- Kafka, or any log.
- Append only.
- Processing as a stream.
- Playback to reprocess.
- Architecture with one road.
Be careful with
- Retention shorter than your bugs.
- Replay time.
- Side effects.
- Calls to systems that changed since.