• Stars
    star
    105
  • Rank 316,817 (Top 7 %)
  • Language
    Scala
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Event sourcing journal implementation using Kafka as main storage

Kafka Journal

Build Status Coverage Status Codacy Badge Version Chat

Stream data from two sources where one is eventually consistent and the other one loses its tail

This library provides ability to use kafka as storage for events. Kafka is a perfect fit in case you want to have streaming capabilities for your events However it also uses cassandra to keep data access performance on acceptable level and overcome kafka retention policy Cassandra is a default choice, but you may use any other storage which satisfies following interfaces:

High level idea

Writing events flow:

  1. Journal client publishes events to kafka
  2. Replicator app stores events to cassandra

Reading events flow:

  1. Client publishes special marker to kafka so we can make sure there are no more events to expect
  2. Client reads events from cassandra, however at this point we are not yet sure that all events are replicated from kafka to cassandra
  3. Client read events from kafka using offset of last event found in cassandra
  4. We consider recovery finished when marker found in kafka

Notes

  • Kafka topic may be used for many different entities
  • We don't need to store all events in kafka as long as they are in cassandra
  • We do not cover snapshots yet
  • Replicator is a separate application
  • It is easy to replace cassandra here with some relational database

State recovery performance

Reading events performance depends on finding the closest offset to the marker as well on replication latency (time difference between the moment event has been written to kafka and the moment when event gets into cassandra)

We may share same kafka consumer for many simultaneous recoveries

Read & write capabilities:

  • Client allowed to read + write kafka and read cassandra
  • Replicator allowed to read kafka and read + write cassandra

Hence, we recommend configuring access rights accordingly.

Api

trait Journals[F[_]] {

  def apply(key: Key): Journal[F]
}

trait Journal[F[_]] {

  /**
   * @param expireAfter Define expireAfter in order to expire whole journal for given entity
   */
  def append(
    events: Nel[Event],
    expireAfter: Option[ExpireAfter],
    metadata: Option[JsValue],
    headers: Headers
  ): F[PartitionOffset]

  def read(from: SeqNr): Stream[F, EventRecord]

  def pointer: F[Option[SeqNr]]

  /**
   * Deletes events up to provided SeqNr, consecutive pointer call will return last seen value  
   */
  def delete(to: DeleteTo): F[Option[PartitionOffset]]

  /**
   * Deletes all data with regards to journal, consecutive pointer call will return none
   */
  def purge: F[Option[PartitionOffset]]
}

Troubleshooting

Kafka exceptions in logs

Kafka client tends to log some exceptions at error level, however in reality those are harmless in case of operation retried successfully. Retriable exceptions usually extend RetriableException

Here is the list of known error logs you may ignore:

  • Offset commit failed on partition .. at offset ..: The request timed out.
  • Offset commit failed on partition .. at offset ..: The coordinator is loading and hence can't process requests.
  • Offset commit failed on partition .. at offset ..: This is not the correct coordinator.
  • Offset commit failed on partition .. at offset ..: This server does not host this topic-partition.

Akka persistence plugin

In order to use kafka-journal as akka persistence plugin you would need to add following to your *.conf file:

akka.persistence.journal.plugin = "evolutiongaming.kafka-journal.persistence.journal"

Unfortunately akka persistence snapshot plugin is not implemented yet.

Setup

addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2")

libraryDependencies += "com.evolutiongaming" %% "kafka-journal" % "0.0.153"

libraryDependencies += "com.evolutiongaming" %% "kafka-journal-persistence" % "0.0.153"

libraryDependencies += "com.evolutiongaming" %% "kafka-journal-replicator" % "0.0.153"

libraryDependencies += "com.evolutiongaming" %% "kafka-journal-eventual-cassandra" % "0.0.153"

Presentations

More Repositories

1

scala-bootcamp

Scala Bootcamp
Scala
133
star
2

tsc-silent

`tsc` with `--suppress` flag
TypeScript
72
star
3

kryo-macros

Scala macros for compile-time generation of Kryo serializers
Scala
58
star
4

typescript-bootcamp

TypeScript bootcamp
CSS
54
star
5

scache

Cache in Scala with cats-effect
Scala
50
star
6

skafka

Scala wrapper for kafka consumer and producer
Scala
43
star
7

akka-effect

Cats-Effect & Akka interop
Scala
41
star
8

derivation

Configured derivation library for scala 3
Scala
35
star
9

cats-helper

Helpers for cats & cats-effect
Scala
24
star
10

babylonjs-texture-generator

A tool that generates PVRTC, ETC1, ETC2, ASTC textures from png and jpg files.
TypeScript
22
star
11

akka-http-documenteddsl

Autodocumented Directives fo akka-http.
Scala
19
star
12

kafka-flow

library for reliable processing records received from kafka
Scala
18
star
13

scassandra

Cassandra client in scala
Scala
12
star
14

babylonjs-make-incremental

Node version of babylonjs make incremental script
TypeScript
9
star
15

ease

Encoder Evaluation Suite (ease)
Go
8
star
16

safe-akka

Safe Akka
Scala
8
star
17

akka-tools

akka-tools
Scala
8
star
18

smetrics

Generic interface to abstract from metrics vendors and their implementations
Scala
8
star
19

play-json-tools

Play-Json helpers
Scala
7
star
20

evoneering

The official portal for Evolution Gaming, Department of Engineering.
TypeScript
7
star
21

scala-tools

scala-tools
Scala
7
star
22

sharding-strategy

Custom sharding strategies for akka cluster
Scala
7
star
23

sstream

Stream
Scala
7
star
24

recruitment

Recruitment homework tasks
TypeScript
7
star
25

throttler

Request throttler
Scala
6
star
26

clickhouse-scala

Alternative driver to ClickHouse via native tcp protocol
Scala
6
star
27

patch

Patch is a building block for event-sourcing
Scala
6
star
28

stracer

Tools for tracing and span reporting
Scala
6
star
29

typed-recompose

TypeScript
6
star
30

no-log4j-test

Test to verify that your project has no log4j dependency
Scala
5
star
31

retry

Library for retrying failed calls
Scala
5
star
32

kafka-launcher

Kafka launcher
Scala
5
star
33

cassandra-reaper-api

Cassandra Reaper API
Python
5
star
34

conhub

Connection hub implementation on top of akka remoting
Scala
4
star
35

cassandra-sync

Synchronization mechanism via locks stored in cassandra
Scala
4
star
36

sbt-scalac-opts-plugin

sbt-scalac-opts-plugin
Scala
4
star
37

crypto

crypto
Scala
4
star
38

sequentially

Constructions to run tasks sequentially
Scala
3
star
39

ddata-tools

Tools to work with akka distributed data
Scala
3
star
40

cassam

Cassandra migrations
Scala
3
star
41

cassandra-reaper-cli

Cassandra Reaper CLI
Python
3
star
42

gulp-bem-my-style

Turn your CSS files into JS based BEM definition
JavaScript
2
star
43

hostname

Provide hostname in scala/java
Scala
2
star
44

prometheus-cassandra-driver

Idiomatic Prometheus collector for Cassandra Java driver metrics
Java
2
star
45

react-bem-my-style

Turn CSS into React-eatable BEM
CoffeeScript
2
star
46

config-tools

Typesafe config helpers
Scala
2
star
47

js-benchmark

Benchmark plugin for measuring FPS of JavaScript animations and RAM
JavaScript
2
star
48

json-partial-update

Play Json extension supporting partial updates
Scala
2
star
49

sbt-artifactory-plugin

Scala
2
star
50

random

Pure random number generator
Scala
2
star
51

pubsub

PubSub typesafe abstraction on top of akka DistributedPubSubMediator
Scala
2
star
52

stream-journal-to-kafka

Akka persistent journal extension which streams persisted events to kafka
Scala
1
star
53

akka-http-play-json

PlayJson integration for AkkaHttp
Scala
1
star
54

serially

Scala
1
star
55

prometheus-tools

Prometheus client tools
Scala
1
star
56

sbt-git-stamp

Scala
1
star
57

fs2-workshop

Scala
1
star
58

cassandra-launcher

Cassandra launcher
Scala
1
star
59

metered-scaffeine

scaffeine cache integrated with dropwizzard metrics and support for scala ExecutionContext
Scala
1
star
60

future-helper

Scala
1
star
61

async

Wrapper for Future to overcome forced asynchrony in `map` & `flatMap` calls
Scala
1
star
62

akka-cluster-tests

Multi-node tests to test various cluster configurations (e.g. sharding configurations).
Scala
1
star
63

test-util

Scala
1
star
64

prometheus-exporter

Scala
1
star
65

nel

Non Empty List
Scala
1
star
66

tmp-dir

Temporary directory util
Scala
1
star
67

BabylonJS-Godrays

Fast, spectacular, configurable and lightweight god rays plugin for BabylonJS
TypeScript
1
star
68

executor-tools

Scala
1
star