You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Olivier Lalonde <ol...@gmail.com> on 2016/05/17 07:18:26 UTC

Kafka for event sourcing architecture

Hi all,

I am considering adopting an "event sourcing" architecture for a system I
am developing and Kafka seems like a good choice of store for events.

For those who aren't aware, this architecture style consists in storing all
state changes of the system as an ordered log of events and building
derivative views as needed for easier querying (using a SQL database for
example). Those views must be completely derived from the event log alone
so that the log effectively becomes a "single source of truth".

I was wondering if anyone else is using Kafka for that purpose and more
specifically:

1) Can Kafka store messages permanently?

2) Let's say I throw away my derived view and want to re-build it from
scratch, is it possible to consume messages from a topic from its very
first message and once it has caught up, listen for new messages like it
would normally do?

2) Does it support transactions? Let's say I want to push 3 messages
atomically but the producer process crashes after sending only 2 messages,
is it possible to "rollback" the first 2 messages (e.g. "all or nothing"
semantics)?

3) Does it support request/response style semantics or can they be
simulated? My system's primary interface with the outside world is an HTTP
API so it would be nice if I could publish an event and wait for all the
internal services which need to process the event to be "done"
processing before returning a response.

PS: I'm a Node.js/Go developer so when possible please avoid Java centric
terminology.

Thanks!

- Oli

-- 
- Oli

Olivier Lalonde
http://www.syskall.com <-- connect with me!

Re: Kafka for event sourcing architecture

Posted by "Tauzell, Dave" <Da...@surescripts.com>.
You might also look at the Apache bookkeeper project which is a distributed log, but a more low-level interface.

> On May 17, 2016, at 19:57, Olivier Lalonde <ol...@gmail.com> wrote:
>
> Thanks all for the detailed answer Tom and everyone else who replied. I
> will look into Pintrest's secor.
>
> The use case I'm trying to achieve here is probably different than what
> most people seem to use Kafka for and it might be the wrong tool for the
> job. I'm actually don't really need high scalability at all (for now), and
> am more interested in the log model for conceptual reasons. I'm building a
> web app for a really early stage startup that has very low volumes of usage
> and data for now (mostly CRUD stuff - change profile name, email,
> add/update post, etc.) but having worked a lot with React/Redux and Bitcoin
> recently, I've become seduced by the idea of having a single source of
> truth (an event log) from which all the application state can be
> constructed at any point in time. It makes a tons of things easier:
>
> - no need for database migrations (we can just build a new database by
> replaying the event log - well if you have a large log, snapshots can help
> speed things up!)
> - easier to load data into different systems (PostgreSQL for most queries,
> elasticsearch for search, each system just needs to have glue code that
> reads the event log and possibly replay past events if the system is added
> later on, etc.)
> - it can be use as a point of communication and synchronisation between
> multiple microservices
> - perfect audit trail, no data lost (really important for us as we will be
> handling financial transactions)
> - etc.
>
> But it introduces some new problems:
>
> - unfamiliar: not a lot of tooling / documentation around this pattern
> - avoiding side effects (e.g. with external systems) when replaying events
> - how to support request/response style requests (e.g. web user changes
> profile name, we receive the http request, put "profile_name_changed" event
> in the log and we need to generate an HTML page with that new profile name
> but that piece of code probably talks to a PostgreSQL database which might
> not have been updated with that new profile name yet, etc.)
> - etc.
>
> Anyways, I might not actually go down that path because it's pretty
> unfamiliar. I was wondering for those of you who use Kafka but only for
> specific types of data (e.g. "user added item to cart", etc.) do you both
> update a database and push an event to the log? Does anyone else use an
> architecture similar to the one I described (e.g. all your databases can
> re-constructed by replaying an event log?).
>
> Thanks again to everyone who replied, this is really helpful!
>
> Cheers,
> Oli
>
>
> On Tue, May 17, 2016 at 5:03 PM, Radoslaw Gruchalski <ra...@gruchalski.com>
> wrote:
>
>> Will do as soon as electricity is back. On edge at the moment.
>>
>> Get Outlook for iOS
>>
>>
>>
>>
>> On Tue, May 17, 2016 at 5:01 PM -0700, "Christian Posta" <
>> christian.posta@gmail.com> wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Please create a JIRA with your thoughts. I'd be happy to help out with
>> something like that.
>>
>> On Tue, May 17, 2016 at 4:57 PM, Radoslaw Gruchalski
>> wrote:
>>
>>> Not as far as I'm aware. I'd be happy to contribute if there is a desire
>>> to have such feature. From experience with other projects, I know that
>>> without the initial pitch / discussion, it could be difficult to get such
>>> feature in. I can create a jira in the morning, no electricity again
>>> tonight :-/
>>>
>>> Get Outlook for iOS
>>>
>>>
>>>
>>>
>>> On Tue, May 17, 2016 at 4:53 PM -0700, "Christian Posta" <
>>> christian.posta@gmail.com> wrote:
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> +1 to your solution of log.cleanup.policy. Other brokers (ie, ActiveMQ)
>>> have a feature like that.
>>> Is there a JIRA for this?
>>>
>>> On Tue, May 17, 2016 at 4:48 PM, Radoslaw Gruchalski
>>> wrote:
>>>
>>>> I have described a cold storage solution for Kafka:
>>>>
>>>
>> https://medium.com/@rad_g/the-case-for-kafka-cold-storage-32929d0a57b2#.kf0jf8cwv
>>> .
>>>> Also described it here a couple of times. Thd potential solution seems
>>>> rather straightforward.
>>>> Get Outlook for iOS
>>>>
>>>>    _____________________________
>>>> From: Luke Steensen
>>>> Sent: Tuesday, May 17, 2016 11:22 pm
>>>> Subject: Re: Kafka for event sourcing architecture
>>>> To:
>>>>
>>>>
>>>> It's harder in Kafka because the unit of replication is an entire
>>>> partition, not a single key/value pair. Partitions are large and
>>> constantly
>>>> growing, where key/value pairs are typically much smaller and don't
>>> change
>>>> in size. There would theoretically be no difference if you had one
>>>> partition per key, but that's not practical. Instead, you end up trying
>>> to
>>>> pick a number of partitions big enough that they'll each be a
>> reasonable
>>>> size for the foreseeable future but not so big that the cluster
>> overhead
>>> is
>>>> untenable. Even then the clock is ticking towards the day your biggest
>>>> partition approaches the limit of storage available on a single
>> machine.
>>>>
>>>> It's frustrating because, as you say, there would be enormous benefits
>> to
>>>> being able to access all data through the same system. Unfortunately,
>> it
>>>> seems too far away from Kafka's original use case to be practical.
>>>>
>>>>
>>>> On Tue, May 17, 2016 at 12:32 PM, Daniel Schierbeck <
>>>> dasch@zendesk.com.invalid> wrote:
>>>>
>>>>> I'm not sure why Kafka at least in theory cannot be used for infinite
>>>>> retention – any replicated database system would need to have a new
>>> node
>>>>> ingest all the data from failed node from its replicas. Surely this
>> is
>>> no
>>>>> different in S3 itself. Why is this harder to do in Kafka than in
>> other
>>>>> systems? The benefit of having just a single message log system would
>>> be
>>>>> rather big.
>>>>>
>>>>> On Tue, May 17, 2016 at 4:44 AM Tom Crayford
>>>> wrote:
>>>>>
>>>>>> Hi Oli,
>>>>>>
>>>>>> Inline.
>>>>>>
>>>>>>> On Tuesday, 17 May 2016, Olivier Lalonde  wrote:
>>>>>>>
>>>>>>> Hi all,
>>>>>>>
>>>>>>> I am considering adopting an "event sourcing" architecture for a
>>>>> system I
>>>>>>> am developing and Kafka seems like a good choice of store for
>>> events.
>>>>>>>
>>>>>>> For those who aren't aware, this architecture style consists in
>>>> storing
>>>>>> all
>>>>>>> state changes of the system as an ordered log of events and
>>> building
>>>>>>> derivative views as needed for easier querying (using a SQL
>>> database
>>>>> for
>>>>>>> example). Those views must be completely derived from the event
>> log
>>>>> alone
>>>>>>> so that the log effectively becomes a "single source of truth".
>>>>>>>
>>>>>>> I was wondering if anyone else is using Kafka for that purpose
>> and
>>>> more
>>>>>>> specifically:
>>>>>>>
>>>>>>> 1) Can Kafka store messages permanently?
>>>>>>
>>>>>>
>>>>>> No. Whilst you can tweak config and such to get a very long
>> retention
>>>>>> period, this doesn't work well with Kafka at all. Keeping data
>> around
>>>>>> forever has severe impacts on the operability of your cluster. For
>>>>> example,
>>>>>> if a machine fails, a replacement would have to catch up with vast
>>>>>> quantities of data from its replicas. Currently we (Heroku Kafka)
>>>>> restrict
>>>>>> our customers to a maximum of 14 days of retention, because of all
>>> the
>>>>>> operational headaches of more retention than that. Of course on
>> your
>>>> own
>>>>>> cluster you *can* set it as high as you like, this is just an
>>> anecdotal
>>>>>> experience thing from a team that runs thousands of clusters -
>>> infinite
>>>>>> retention is an operational disaster waiting to happen.
>>>>>>
>>>>>> Whilst Kafka does have a replay mechanism, that should mostly be
>>> though
>>>>> of
>>>>>> as a mechanism for handling other system failures. E.g. If the
>>> database
>>>>> you
>>>>>> store indexed views is is down, Kafka's replay and retention
>>> mechanisms
>>>>>> mean you're not losing data whilst restoring the availability of
>> that
>>>>>> database.
>>>>>>
>>>>>> What we typically suggest customers do when they ask about this use
>>>> case
>>>>> is
>>>>>> to use Kafka as a messaging system, but use e.g. S3 as the long
>> term
>>>>> store.
>>>>>> Kafka can help with batching writes up to S3 (see e.g. Pintrest's
>>> secor
>>>>>> project), and act as a very high throughput, durable, replicated
>>>>> messaging
>>>>>> layer for communication. In this paradigm, when you want to replay,
>>> you
>>>>> do
>>>>>> so out of S3 until you've consumed the last offset there, then
>> start
>>>>>> replaying out of and catching up with the small amount of remaining
>>>> data
>>>>> in
>>>>>> Kafka. Of course the replay logic there has to be hand rolled, as
>>> Kafka
>>>>> and
>>>>>> its clients have no knowledge of external stores.
>>>>>>
>>>>>> Another potential thing to look at is Kafka's compacted topic
>>>> mechanism.
>>>>>> With compacted topics, Kafka keeps the latest element for a given
>>> key,
>>>>>> making it act a little more like a database table. Note that you
>>> still
>>>>> have
>>>>>> to consume by offset here - there's no "get the value for key Y
>>>>>> operation". However, this assumes that your keyspace is still
>>> tractably
>>>>>> small, and that you're ok with keeping only the latest value.
>>>> Compaction
>>>>>> completely overrides time based retention, so you have to "delete"
>>> keys
>>>>> or
>>>>>> have a bounded keyspace if you want to retain operational sanity
>> with
>>>>>> Kafka. I'd recommend reading the docs on compacted topics, they
>> cover
>>>> the
>>>>>> use cases quite well.
>>>>>>
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> 2) Let's say I throw away my derived view and want to re-build it
>>>> from
>>>>>>> scratch, is it possible to consume messages from a topic from its
>>>> very
>>>>>>> first message and once it has caught up, listen for new messages
>>> like
>>>>> it
>>>>>>> would normally do?
>>>>>>
>>>>>>
>>>>>> That's entirely possible, you can catch up from the first retained
>>>>> message
>>>>>> and then continue from there very easily. However, see above about
>>>>> infinite
>>>>>> retention.
>>>>>>
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> 2) Does it support transactions? Let's say I want to push 3
>>> messages
>>>>>>> atomically but the producer process crashes after sending only 2
>>>>>> messages,
>>>>>>> is it possible to "rollback" the first 2 messages (e.g. "all or
>>>>> nothing"
>>>>>>> semantics)?
>>>>>>
>>>>>>
>>>>>> No. Kafka at the moment only supports "at least once" semantics,
>> and
>>>>> there
>>>>>> are no cross broker transactions of any kind. Implementing such a
>>> thing
>>>>>> would likely have huge negative impacts on the current performance
>>>>>> characteristics of Kafka, which would be a issue for many users.
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> 3) Does it support request/response style semantics or can they
>> be
>>>>>>> simulated? My system's primary interface with the outside world
>> is
>>> an
>>>>>> HTTP
>>>>>>> API so it would be nice if I could publish an event and wait for
>>> all
>>>>> the
>>>>>>> internal services which need to process the event to be "done"
>>>>>>> processing before returning a response.
>>>>>>
>>>>>>
>>>>>>
>>>>>> In theory that's possible - the producer can return the offset of
>> the
>>>>>> message produced, and you could check the latest offset of each
>>>> consumer
>>>>> in
>>>>>> your web request handler.
>>>>>>
>>>>>> However, doing so is not going to work that well, unless you're ok
>>> with
>>>>>> your web requests taking on the order of seconds to tens of seconds
>>> to
>>>>>> fulfill. Kafka can do low latency messaging reasonably well, but
>>>>>> coordinating the offsets of many consumers would likely have a huge
>>>>> latency
>>>>>> impact. Writing the code for it and getting it handling failure
>>>> correctly
>>>>>> would likely be a lot of work (there's nothing in any of the client
>>>>>> libraries like this, because it is not a desirable or supported use
>>>>> case).
>>>>>>
>>>>>> Instead I'd like to query *why* you need those semantics? What's
>> the
>>>>> issue
>>>>>> with just producing a message and telling the user HTTP 200 and
>> later
>>>>>> consuming it.
>>>>>>
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> PS: I'm a Node.js/Go developer so when possible please avoid Java
>>>>> centric
>>>>>>> terminology.
>>>>>>
>>>>>>
>>>>>> Please to note that the node and go clients are notably less mature
>>>> than
>>>>>> the JVM clients, and that running Kafka in production means knowing
>>>>> enough
>>>>>> about the JVM and Zookeeper to handle that.
>>>>>>
>>>>>> Thanks!
>>>>>> Tom Crayford
>>>>>> Heroku Kafka
>>>>>>
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>> - Oli
>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> - Oli
>>>>>>>
>>>>>>> Olivier Lalonde
>>>>>>> http://www.syskall.com
>>>>>> <-- connect with me!
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> *Christian Posta*
>>> twitter: @christianposta
>>> http://www.christianposta.com/blog
>>> http://fabric8.io
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>> --
>> *Christian Posta*
>> twitter: @christianposta
>> http://www.christianposta.com/blog
>> http://fabric8.io
>>
>>
>>
>>
>>
>>
>
>
> --
> - Oli
>
> Olivier Lalonde
> http://www.syskall.com <-- connect with me!
This e-mail and any files transmitted with it are confidential, may contain sensitive information, and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error, please notify the sender by reply e-mail immediately and destroy all copies of the e-mail and any attachments.

Re: Kafka for event sourcing architecture

Posted by Olivier Lalonde <ol...@gmail.com>.
Thanks all for the detailed answer Tom and everyone else who replied. I
will look into Pintrest's secor.

The use case I'm trying to achieve here is probably different than what
most people seem to use Kafka for and it might be the wrong tool for the
job. I'm actually don't really need high scalability at all (for now), and
am more interested in the log model for conceptual reasons. I'm building a
web app for a really early stage startup that has very low volumes of usage
and data for now (mostly CRUD stuff - change profile name, email,
add/update post, etc.) but having worked a lot with React/Redux and Bitcoin
recently, I've become seduced by the idea of having a single source of
truth (an event log) from which all the application state can be
constructed at any point in time. It makes a tons of things easier:

- no need for database migrations (we can just build a new database by
replaying the event log - well if you have a large log, snapshots can help
speed things up!)
- easier to load data into different systems (PostgreSQL for most queries,
elasticsearch for search, each system just needs to have glue code that
reads the event log and possibly replay past events if the system is added
later on, etc.)
- it can be use as a point of communication and synchronisation between
multiple microservices
- perfect audit trail, no data lost (really important for us as we will be
handling financial transactions)
- etc.

But it introduces some new problems:

- unfamiliar: not a lot of tooling / documentation around this pattern
- avoiding side effects (e.g. with external systems) when replaying events
- how to support request/response style requests (e.g. web user changes
profile name, we receive the http request, put "profile_name_changed" event
in the log and we need to generate an HTML page with that new profile name
but that piece of code probably talks to a PostgreSQL database which might
not have been updated with that new profile name yet, etc.)
- etc.

Anyways, I might not actually go down that path because it's pretty
unfamiliar. I was wondering for those of you who use Kafka but only for
specific types of data (e.g. "user added item to cart", etc.) do you both
update a database and push an event to the log? Does anyone else use an
architecture similar to the one I described (e.g. all your databases can
re-constructed by replaying an event log?).

Thanks again to everyone who replied, this is really helpful!

Cheers,
Oli


On Tue, May 17, 2016 at 5:03 PM, Radoslaw Gruchalski <ra...@gruchalski.com>
wrote:

> Will do as soon as electricity is back. On edge at the moment.
>
> Get Outlook for iOS
>
>
>
>
> On Tue, May 17, 2016 at 5:01 PM -0700, "Christian Posta" <
> christian.posta@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
> Please create a JIRA with your thoughts. I'd be happy to help out with
> something like that.
>
> On Tue, May 17, 2016 at 4:57 PM, Radoslaw Gruchalski
> wrote:
>
> > Not as far as I'm aware. I'd be happy to contribute if there is a desire
> > to have such feature. From experience with other projects, I know that
> > without the initial pitch / discussion, it could be difficult to get such
> > feature in. I can create a jira in the morning, no electricity again
> > tonight :-/
> >
> > Get Outlook for iOS
> >
> >
> >
> >
> > On Tue, May 17, 2016 at 4:53 PM -0700, "Christian Posta" <
> > christian.posta@gmail.com> wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > +1 to your solution of log.cleanup.policy. Other brokers (ie, ActiveMQ)
> > have a feature like that.
> > Is there a JIRA for this?
> >
> > On Tue, May 17, 2016 at 4:48 PM, Radoslaw Gruchalski
> > wrote:
> >
> > > I have described a cold storage solution for Kafka:
> > >
> >
> https://medium.com/@rad_g/the-case-for-kafka-cold-storage-32929d0a57b2#.kf0jf8cwv
> > .
> > > Also described it here a couple of times. Thd potential solution seems
> > > rather straightforward.
> > > Get Outlook for iOS
> > >
> > >     _____________________________
> > > From: Luke Steensen
> > > Sent: Tuesday, May 17, 2016 11:22 pm
> > > Subject: Re: Kafka for event sourcing architecture
> > > To:
> > >
> > >
> > > It's harder in Kafka because the unit of replication is an entire
> > > partition, not a single key/value pair. Partitions are large and
> > constantly
> > > growing, where key/value pairs are typically much smaller and don't
> > change
> > > in size. There would theoretically be no difference if you had one
> > > partition per key, but that's not practical. Instead, you end up trying
> > to
> > > pick a number of partitions big enough that they'll each be a
> reasonable
> > > size for the foreseeable future but not so big that the cluster
> overhead
> > is
> > > untenable. Even then the clock is ticking towards the day your biggest
> > > partition approaches the limit of storage available on a single
> machine.
> > >
> > > It's frustrating because, as you say, there would be enormous benefits
> to
> > > being able to access all data through the same system. Unfortunately,
> it
> > > seems too far away from Kafka's original use case to be practical.
> > >
> > >
> > > On Tue, May 17, 2016 at 12:32 PM, Daniel Schierbeck <
> > > dasch@zendesk.com.invalid> wrote:
> > >
> > > > I'm not sure why Kafka at least in theory cannot be used for infinite
> > > > retention – any replicated database system would need to have a new
> > node
> > > > ingest all the data from failed node from its replicas. Surely this
> is
> > no
> > > > different in S3 itself. Why is this harder to do in Kafka than in
> other
> > > > systems? The benefit of having just a single message log system would
> > be
> > > > rather big.
> > > >
> > > > On Tue, May 17, 2016 at 4:44 AM Tom Crayford
> > > wrote:
> > > >
> > > > > Hi Oli,
> > > > >
> > > > > Inline.
> > > > >
> > > > > On Tuesday, 17 May 2016, Olivier Lalonde  wrote:
> > > > >
> > > > > > Hi all,
> > > > > >
> > > > > > I am considering adopting an "event sourcing" architecture for a
> > > > system I
> > > > > > am developing and Kafka seems like a good choice of store for
> > events.
> > > > > >
> > > > > > For those who aren't aware, this architecture style consists in
> > > storing
> > > > > all
> > > > > > state changes of the system as an ordered log of events and
> > building
> > > > > > derivative views as needed for easier querying (using a SQL
> > database
> > > > for
> > > > > > example). Those views must be completely derived from the event
> log
> > > > alone
> > > > > > so that the log effectively becomes a "single source of truth".
> > > > > >
> > > > > > I was wondering if anyone else is using Kafka for that purpose
> and
> > > more
> > > > > > specifically:
> > > > > >
> > > > > > 1) Can Kafka store messages permanently?
> > > > >
> > > > >
> > > > > No. Whilst you can tweak config and such to get a very long
> retention
> > > > > period, this doesn't work well with Kafka at all. Keeping data
> around
> > > > > forever has severe impacts on the operability of your cluster. For
> > > > example,
> > > > > if a machine fails, a replacement would have to catch up with vast
> > > > > quantities of data from its replicas. Currently we (Heroku Kafka)
> > > > restrict
> > > > > our customers to a maximum of 14 days of retention, because of all
> > the
> > > > > operational headaches of more retention than that. Of course on
> your
> > > own
> > > > > cluster you *can* set it as high as you like, this is just an
> > anecdotal
> > > > > experience thing from a team that runs thousands of clusters -
> > infinite
> > > > > retention is an operational disaster waiting to happen.
> > > > >
> > > > > Whilst Kafka does have a replay mechanism, that should mostly be
> > though
> > > > of
> > > > > as a mechanism for handling other system failures. E.g. If the
> > database
> > > > you
> > > > > store indexed views is is down, Kafka's replay and retention
> > mechanisms
> > > > > mean you're not losing data whilst restoring the availability of
> that
> > > > > database.
> > > > >
> > > > > What we typically suggest customers do when they ask about this use
> > > case
> > > > is
> > > > > to use Kafka as a messaging system, but use e.g. S3 as the long
> term
> > > > store.
> > > > > Kafka can help with batching writes up to S3 (see e.g. Pintrest's
> > secor
> > > > > project), and act as a very high throughput, durable, replicated
> > > > messaging
> > > > > layer for communication. In this paradigm, when you want to replay,
> > you
> > > > do
> > > > > so out of S3 until you've consumed the last offset there, then
> start
> > > > > replaying out of and catching up with the small amount of remaining
> > > data
> > > > in
> > > > > Kafka. Of course the replay logic there has to be hand rolled, as
> > Kafka
> > > > and
> > > > > its clients have no knowledge of external stores.
> > > > >
> > > > > Another potential thing to look at is Kafka's compacted topic
> > > mechanism.
> > > > > With compacted topics, Kafka keeps the latest element for a given
> > key,
> > > > > making it act a little more like a database table. Note that you
> > still
> > > > have
> > > > > to consume by offset here - there's no "get the value for key Y
> > > > > operation". However, this assumes that your keyspace is still
> > tractably
> > > > > small, and that you're ok with keeping only the latest value.
> > > Compaction
> > > > > completely overrides time based retention, so you have to "delete"
> > keys
> > > > or
> > > > > have a bounded keyspace if you want to retain operational sanity
> with
> > > > > Kafka. I'd recommend reading the docs on compacted topics, they
> cover
> > > the
> > > > > use cases quite well.
> > > > >
> > > > >
> > > > >
> > > > > >
> > > > > > 2) Let's say I throw away my derived view and want to re-build it
> > > from
> > > > > > scratch, is it possible to consume messages from a topic from its
> > > very
> > > > > > first message and once it has caught up, listen for new messages
> > like
> > > > it
> > > > > > would normally do?
> > > > >
> > > > >
> > > > > That's entirely possible, you can catch up from the first retained
> > > > message
> > > > > and then continue from there very easily. However, see above about
> > > > infinite
> > > > > retention.
> > > > >
> > > > >
> > > > >
> > > > > >
> > > > > > 2) Does it support transactions? Let's say I want to push 3
> > messages
> > > > > > atomically but the producer process crashes after sending only 2
> > > > > messages,
> > > > > > is it possible to "rollback" the first 2 messages (e.g. "all or
> > > > nothing"
> > > > > > semantics)?
> > > > >
> > > > >
> > > > > No. Kafka at the moment only supports "at least once" semantics,
> and
> > > > there
> > > > > are no cross broker transactions of any kind. Implementing such a
> > thing
> > > > > would likely have huge negative impacts on the current performance
> > > > > characteristics of Kafka, which would be a issue for many users.
> > > > >
> > > > >
> > > > > >
> > > > > > 3) Does it support request/response style semantics or can they
> be
> > > > > > simulated? My system's primary interface with the outside world
> is
> > an
> > > > > HTTP
> > > > > > API so it would be nice if I could publish an event and wait for
> > all
> > > > the
> > > > > > internal services which need to process the event to be "done"
> > > > > > processing before returning a response.
> > > > >
> > > > >
> > > > >
> > > > > In theory that's possible - the producer can return the offset of
> the
> > > > > message produced, and you could check the latest offset of each
> > > consumer
> > > > in
> > > > > your web request handler.
> > > > >
> > > > > However, doing so is not going to work that well, unless you're ok
> > with
> > > > > your web requests taking on the order of seconds to tens of seconds
> > to
> > > > > fulfill. Kafka can do low latency messaging reasonably well, but
> > > > > coordinating the offsets of many consumers would likely have a huge
> > > > latency
> > > > > impact. Writing the code for it and getting it handling failure
> > > correctly
> > > > > would likely be a lot of work (there's nothing in any of the client
> > > > > libraries like this, because it is not a desirable or supported use
> > > > case).
> > > > >
> > > > > Instead I'd like to query *why* you need those semantics? What's
> the
> > > > issue
> > > > > with just producing a message and telling the user HTTP 200 and
> later
> > > > > consuming it.
> > > > >
> > > > >
> > > > >
> > > > > >
> > > > > > PS: I'm a Node.js/Go developer so when possible please avoid Java
> > > > centric
> > > > > > terminology.
> > > > >
> > > > >
> > > > > Please to note that the node and go clients are notably less mature
> > > than
> > > > > the JVM clients, and that running Kafka in production means knowing
> > > > enough
> > > > > about the JVM and Zookeeper to handle that.
> > > > >
> > > > > Thanks!
> > > > > Tom Crayford
> > > > > Heroku Kafka
> > > > >
> > > > > >
> > > > > > Thanks!
> > > > > >
> > > > > > - Oli
> > > > >
> > > > > >
> > > > > > --
> > > > > > - Oli
> > > > > >
> > > > > > Olivier Lalonde
> > > > > > http://www.syskall.com
> > > > >  <-- connect with me!
> > > > > >
> > > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> > --
> > *Christian Posta*
> > twitter: @christianposta
> > http://www.christianposta.com/blog
> > http://fabric8.io
> >
> >
> >
> >
> >
> >
>
>
> --
> *Christian Posta*
> twitter: @christianposta
> http://www.christianposta.com/blog
> http://fabric8.io
>
>
>
>
>
>


-- 
- Oli

Olivier Lalonde
http://www.syskall.com <-- connect with me!

Re: Kafka for event sourcing architecture

Posted by Radoslaw Gruchalski <ra...@gruchalski.com>.
Will do as soon as electricity is back. On edge at the moment.

Get Outlook for iOS




On Tue, May 17, 2016 at 5:01 PM -0700, "Christian Posta" <ch...@gmail.com> wrote:










Please create a JIRA with your thoughts. I'd be happy to help out with
something like that.

On Tue, May 17, 2016 at 4:57 PM, Radoslaw Gruchalski 
wrote:

> Not as far as I'm aware. I'd be happy to contribute if there is a desire
> to have such feature. From experience with other projects, I know that
> without the initial pitch / discussion, it could be difficult to get such
> feature in. I can create a jira in the morning, no electricity again
> tonight :-/
>
> Get Outlook for iOS
>
>
>
>
> On Tue, May 17, 2016 at 4:53 PM -0700, "Christian Posta" <
> christian.posta@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
> +1 to your solution of log.cleanup.policy. Other brokers (ie, ActiveMQ)
> have a feature like that.
> Is there a JIRA for this?
>
> On Tue, May 17, 2016 at 4:48 PM, Radoslaw Gruchalski
> wrote:
>
> > I have described a cold storage solution for Kafka:
> >
> https://medium.com/@rad_g/the-case-for-kafka-cold-storage-32929d0a57b2#.kf0jf8cwv
> .
> > Also described it here a couple of times. Thd potential solution seems
> > rather straightforward.
> > Get Outlook for iOS
> >
> >     _____________________________
> > From: Luke Steensen
> > Sent: Tuesday, May 17, 2016 11:22 pm
> > Subject: Re: Kafka for event sourcing architecture
> > To:
> >
> >
> > It's harder in Kafka because the unit of replication is an entire
> > partition, not a single key/value pair. Partitions are large and
> constantly
> > growing, where key/value pairs are typically much smaller and don't
> change
> > in size. There would theoretically be no difference if you had one
> > partition per key, but that's not practical. Instead, you end up trying
> to
> > pick a number of partitions big enough that they'll each be a reasonable
> > size for the foreseeable future but not so big that the cluster overhead
> is
> > untenable. Even then the clock is ticking towards the day your biggest
> > partition approaches the limit of storage available on a single machine.
> >
> > It's frustrating because, as you say, there would be enormous benefits to
> > being able to access all data through the same system. Unfortunately, it
> > seems too far away from Kafka's original use case to be practical.
> >
> >
> > On Tue, May 17, 2016 at 12:32 PM, Daniel Schierbeck <
> > dasch@zendesk.com.invalid> wrote:
> >
> > > I'm not sure why Kafka at least in theory cannot be used for infinite
> > > retention – any replicated database system would need to have a new
> node
> > > ingest all the data from failed node from its replicas. Surely this is
> no
> > > different in S3 itself. Why is this harder to do in Kafka than in other
> > > systems? The benefit of having just a single message log system would
> be
> > > rather big.
> > >
> > > On Tue, May 17, 2016 at 4:44 AM Tom Crayford
> > wrote:
> > >
> > > > Hi Oli,
> > > >
> > > > Inline.
> > > >
> > > > On Tuesday, 17 May 2016, Olivier Lalonde  wrote:
> > > >
> > > > > Hi all,
> > > > >
> > > > > I am considering adopting an "event sourcing" architecture for a
> > > system I
> > > > > am developing and Kafka seems like a good choice of store for
> events.
> > > > >
> > > > > For those who aren't aware, this architecture style consists in
> > storing
> > > > all
> > > > > state changes of the system as an ordered log of events and
> building
> > > > > derivative views as needed for easier querying (using a SQL
> database
> > > for
> > > > > example). Those views must be completely derived from the event log
> > > alone
> > > > > so that the log effectively becomes a "single source of truth".
> > > > >
> > > > > I was wondering if anyone else is using Kafka for that purpose and
> > more
> > > > > specifically:
> > > > >
> > > > > 1) Can Kafka store messages permanently?
> > > >
> > > >
> > > > No. Whilst you can tweak config and such to get a very long retention
> > > > period, this doesn't work well with Kafka at all. Keeping data around
> > > > forever has severe impacts on the operability of your cluster. For
> > > example,
> > > > if a machine fails, a replacement would have to catch up with vast
> > > > quantities of data from its replicas. Currently we (Heroku Kafka)
> > > restrict
> > > > our customers to a maximum of 14 days of retention, because of all
> the
> > > > operational headaches of more retention than that. Of course on your
> > own
> > > > cluster you *can* set it as high as you like, this is just an
> anecdotal
> > > > experience thing from a team that runs thousands of clusters -
> infinite
> > > > retention is an operational disaster waiting to happen.
> > > >
> > > > Whilst Kafka does have a replay mechanism, that should mostly be
> though
> > > of
> > > > as a mechanism for handling other system failures. E.g. If the
> database
> > > you
> > > > store indexed views is is down, Kafka's replay and retention
> mechanisms
> > > > mean you're not losing data whilst restoring the availability of that
> > > > database.
> > > >
> > > > What we typically suggest customers do when they ask about this use
> > case
> > > is
> > > > to use Kafka as a messaging system, but use e.g. S3 as the long term
> > > store.
> > > > Kafka can help with batching writes up to S3 (see e.g. Pintrest's
> secor
> > > > project), and act as a very high throughput, durable, replicated
> > > messaging
> > > > layer for communication. In this paradigm, when you want to replay,
> you
> > > do
> > > > so out of S3 until you've consumed the last offset there, then start
> > > > replaying out of and catching up with the small amount of remaining
> > data
> > > in
> > > > Kafka. Of course the replay logic there has to be hand rolled, as
> Kafka
> > > and
> > > > its clients have no knowledge of external stores.
> > > >
> > > > Another potential thing to look at is Kafka's compacted topic
> > mechanism.
> > > > With compacted topics, Kafka keeps the latest element for a given
> key,
> > > > making it act a little more like a database table. Note that you
> still
> > > have
> > > > to consume by offset here - there's no "get the value for key Y
> > > > operation". However, this assumes that your keyspace is still
> tractably
> > > > small, and that you're ok with keeping only the latest value.
> > Compaction
> > > > completely overrides time based retention, so you have to "delete"
> keys
> > > or
> > > > have a bounded keyspace if you want to retain operational sanity with
> > > > Kafka. I'd recommend reading the docs on compacted topics, they cover
> > the
> > > > use cases quite well.
> > > >
> > > >
> > > >
> > > > >
> > > > > 2) Let's say I throw away my derived view and want to re-build it
> > from
> > > > > scratch, is it possible to consume messages from a topic from its
> > very
> > > > > first message and once it has caught up, listen for new messages
> like
> > > it
> > > > > would normally do?
> > > >
> > > >
> > > > That's entirely possible, you can catch up from the first retained
> > > message
> > > > and then continue from there very easily. However, see above about
> > > infinite
> > > > retention.
> > > >
> > > >
> > > >
> > > > >
> > > > > 2) Does it support transactions? Let's say I want to push 3
> messages
> > > > > atomically but the producer process crashes after sending only 2
> > > > messages,
> > > > > is it possible to "rollback" the first 2 messages (e.g. "all or
> > > nothing"
> > > > > semantics)?
> > > >
> > > >
> > > > No. Kafka at the moment only supports "at least once" semantics, and
> > > there
> > > > are no cross broker transactions of any kind. Implementing such a
> thing
> > > > would likely have huge negative impacts on the current performance
> > > > characteristics of Kafka, which would be a issue for many users.
> > > >
> > > >
> > > > >
> > > > > 3) Does it support request/response style semantics or can they be
> > > > > simulated? My system's primary interface with the outside world is
> an
> > > > HTTP
> > > > > API so it would be nice if I could publish an event and wait for
> all
> > > the
> > > > > internal services which need to process the event to be "done"
> > > > > processing before returning a response.
> > > >
> > > >
> > > >
> > > > In theory that's possible - the producer can return the offset of the
> > > > message produced, and you could check the latest offset of each
> > consumer
> > > in
> > > > your web request handler.
> > > >
> > > > However, doing so is not going to work that well, unless you're ok
> with
> > > > your web requests taking on the order of seconds to tens of seconds
> to
> > > > fulfill. Kafka can do low latency messaging reasonably well, but
> > > > coordinating the offsets of many consumers would likely have a huge
> > > latency
> > > > impact. Writing the code for it and getting it handling failure
> > correctly
> > > > would likely be a lot of work (there's nothing in any of the client
> > > > libraries like this, because it is not a desirable or supported use
> > > case).
> > > >
> > > > Instead I'd like to query *why* you need those semantics? What's the
> > > issue
> > > > with just producing a message and telling the user HTTP 200 and later
> > > > consuming it.
> > > >
> > > >
> > > >
> > > > >
> > > > > PS: I'm a Node.js/Go developer so when possible please avoid Java
> > > centric
> > > > > terminology.
> > > >
> > > >
> > > > Please to note that the node and go clients are notably less mature
> > than
> > > > the JVM clients, and that running Kafka in production means knowing
> > > enough
> > > > about the JVM and Zookeeper to handle that.
> > > >
> > > > Thanks!
> > > > Tom Crayford
> > > > Heroku Kafka
> > > >
> > > > >
> > > > > Thanks!
> > > > >
> > > > > - Oli
> > > >
> > > > >
> > > > > --
> > > > > - Oli
> > > > >
> > > > > Olivier Lalonde
> > > > > http://www.syskall.com
> > > >  <-- connect with me!
> > > > >
> > > >
> > >
> >
> >
> >
> >
> >
>
>
>
> --
> *Christian Posta*
> twitter: @christianposta
> http://www.christianposta.com/blog
> http://fabric8.io
>
>
>
>
>
>


-- 
*Christian Posta*
twitter: @christianposta
http://www.christianposta.com/blog
http://fabric8.io






Re: Kafka for event sourcing architecture

Posted by Christian Posta <ch...@gmail.com>.
Please create a JIRA with your thoughts. I'd be happy to help out with
something like that.

On Tue, May 17, 2016 at 4:57 PM, Radoslaw Gruchalski <ra...@gruchalski.com>
wrote:

> Not as far as I'm aware. I'd be happy to contribute if there is a desire
> to have such feature. From experience with other projects, I know that
> without the initial pitch / discussion, it could be difficult to get such
> feature in. I can create a jira in the morning, no electricity again
> tonight :-/
>
> Get Outlook for iOS
>
>
>
>
> On Tue, May 17, 2016 at 4:53 PM -0700, "Christian Posta" <
> christian.posta@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
> +1 to your solution of log.cleanup.policy. Other brokers (ie, ActiveMQ)
> have a feature like that.
> Is there a JIRA for this?
>
> On Tue, May 17, 2016 at 4:48 PM, Radoslaw Gruchalski
> wrote:
>
> > I have described a cold storage solution for Kafka:
> >
> https://medium.com/@rad_g/the-case-for-kafka-cold-storage-32929d0a57b2#.kf0jf8cwv
> .
> > Also described it here a couple of times. Thd potential solution seems
> > rather straightforward.
> > Get Outlook for iOS
> >
> >     _____________________________
> > From: Luke Steensen
> > Sent: Tuesday, May 17, 2016 11:22 pm
> > Subject: Re: Kafka for event sourcing architecture
> > To:
> >
> >
> > It's harder in Kafka because the unit of replication is an entire
> > partition, not a single key/value pair. Partitions are large and
> constantly
> > growing, where key/value pairs are typically much smaller and don't
> change
> > in size. There would theoretically be no difference if you had one
> > partition per key, but that's not practical. Instead, you end up trying
> to
> > pick a number of partitions big enough that they'll each be a reasonable
> > size for the foreseeable future but not so big that the cluster overhead
> is
> > untenable. Even then the clock is ticking towards the day your biggest
> > partition approaches the limit of storage available on a single machine.
> >
> > It's frustrating because, as you say, there would be enormous benefits to
> > being able to access all data through the same system. Unfortunately, it
> > seems too far away from Kafka's original use case to be practical.
> >
> >
> > On Tue, May 17, 2016 at 12:32 PM, Daniel Schierbeck <
> > dasch@zendesk.com.invalid> wrote:
> >
> > > I'm not sure why Kafka at least in theory cannot be used for infinite
> > > retention – any replicated database system would need to have a new
> node
> > > ingest all the data from failed node from its replicas. Surely this is
> no
> > > different in S3 itself. Why is this harder to do in Kafka than in other
> > > systems? The benefit of having just a single message log system would
> be
> > > rather big.
> > >
> > > On Tue, May 17, 2016 at 4:44 AM Tom Crayford
> > wrote:
> > >
> > > > Hi Oli,
> > > >
> > > > Inline.
> > > >
> > > > On Tuesday, 17 May 2016, Olivier Lalonde  wrote:
> > > >
> > > > > Hi all,
> > > > >
> > > > > I am considering adopting an "event sourcing" architecture for a
> > > system I
> > > > > am developing and Kafka seems like a good choice of store for
> events.
> > > > >
> > > > > For those who aren't aware, this architecture style consists in
> > storing
> > > > all
> > > > > state changes of the system as an ordered log of events and
> building
> > > > > derivative views as needed for easier querying (using a SQL
> database
> > > for
> > > > > example). Those views must be completely derived from the event log
> > > alone
> > > > > so that the log effectively becomes a "single source of truth".
> > > > >
> > > > > I was wondering if anyone else is using Kafka for that purpose and
> > more
> > > > > specifically:
> > > > >
> > > > > 1) Can Kafka store messages permanently?
> > > >
> > > >
> > > > No. Whilst you can tweak config and such to get a very long retention
> > > > period, this doesn't work well with Kafka at all. Keeping data around
> > > > forever has severe impacts on the operability of your cluster. For
> > > example,
> > > > if a machine fails, a replacement would have to catch up with vast
> > > > quantities of data from its replicas. Currently we (Heroku Kafka)
> > > restrict
> > > > our customers to a maximum of 14 days of retention, because of all
> the
> > > > operational headaches of more retention than that. Of course on your
> > own
> > > > cluster you *can* set it as high as you like, this is just an
> anecdotal
> > > > experience thing from a team that runs thousands of clusters -
> infinite
> > > > retention is an operational disaster waiting to happen.
> > > >
> > > > Whilst Kafka does have a replay mechanism, that should mostly be
> though
> > > of
> > > > as a mechanism for handling other system failures. E.g. If the
> database
> > > you
> > > > store indexed views is is down, Kafka's replay and retention
> mechanisms
> > > > mean you're not losing data whilst restoring the availability of that
> > > > database.
> > > >
> > > > What we typically suggest customers do when they ask about this use
> > case
> > > is
> > > > to use Kafka as a messaging system, but use e.g. S3 as the long term
> > > store.
> > > > Kafka can help with batching writes up to S3 (see e.g. Pintrest's
> secor
> > > > project), and act as a very high throughput, durable, replicated
> > > messaging
> > > > layer for communication. In this paradigm, when you want to replay,
> you
> > > do
> > > > so out of S3 until you've consumed the last offset there, then start
> > > > replaying out of and catching up with the small amount of remaining
> > data
> > > in
> > > > Kafka. Of course the replay logic there has to be hand rolled, as
> Kafka
> > > and
> > > > its clients have no knowledge of external stores.
> > > >
> > > > Another potential thing to look at is Kafka's compacted topic
> > mechanism.
> > > > With compacted topics, Kafka keeps the latest element for a given
> key,
> > > > making it act a little more like a database table. Note that you
> still
> > > have
> > > > to consume by offset here - there's no "get the value for key Y
> > > > operation". However, this assumes that your keyspace is still
> tractably
> > > > small, and that you're ok with keeping only the latest value.
> > Compaction
> > > > completely overrides time based retention, so you have to "delete"
> keys
> > > or
> > > > have a bounded keyspace if you want to retain operational sanity with
> > > > Kafka. I'd recommend reading the docs on compacted topics, they cover
> > the
> > > > use cases quite well.
> > > >
> > > >
> > > >
> > > > >
> > > > > 2) Let's say I throw away my derived view and want to re-build it
> > from
> > > > > scratch, is it possible to consume messages from a topic from its
> > very
> > > > > first message and once it has caught up, listen for new messages
> like
> > > it
> > > > > would normally do?
> > > >
> > > >
> > > > That's entirely possible, you can catch up from the first retained
> > > message
> > > > and then continue from there very easily. However, see above about
> > > infinite
> > > > retention.
> > > >
> > > >
> > > >
> > > > >
> > > > > 2) Does it support transactions? Let's say I want to push 3
> messages
> > > > > atomically but the producer process crashes after sending only 2
> > > > messages,
> > > > > is it possible to "rollback" the first 2 messages (e.g. "all or
> > > nothing"
> > > > > semantics)?
> > > >
> > > >
> > > > No. Kafka at the moment only supports "at least once" semantics, and
> > > there
> > > > are no cross broker transactions of any kind. Implementing such a
> thing
> > > > would likely have huge negative impacts on the current performance
> > > > characteristics of Kafka, which would be a issue for many users.
> > > >
> > > >
> > > > >
> > > > > 3) Does it support request/response style semantics or can they be
> > > > > simulated? My system's primary interface with the outside world is
> an
> > > > HTTP
> > > > > API so it would be nice if I could publish an event and wait for
> all
> > > the
> > > > > internal services which need to process the event to be "done"
> > > > > processing before returning a response.
> > > >
> > > >
> > > >
> > > > In theory that's possible - the producer can return the offset of the
> > > > message produced, and you could check the latest offset of each
> > consumer
> > > in
> > > > your web request handler.
> > > >
> > > > However, doing so is not going to work that well, unless you're ok
> with
> > > > your web requests taking on the order of seconds to tens of seconds
> to
> > > > fulfill. Kafka can do low latency messaging reasonably well, but
> > > > coordinating the offsets of many consumers would likely have a huge
> > > latency
> > > > impact. Writing the code for it and getting it handling failure
> > correctly
> > > > would likely be a lot of work (there's nothing in any of the client
> > > > libraries like this, because it is not a desirable or supported use
> > > case).
> > > >
> > > > Instead I'd like to query *why* you need those semantics? What's the
> > > issue
> > > > with just producing a message and telling the user HTTP 200 and later
> > > > consuming it.
> > > >
> > > >
> > > >
> > > > >
> > > > > PS: I'm a Node.js/Go developer so when possible please avoid Java
> > > centric
> > > > > terminology.
> > > >
> > > >
> > > > Please to note that the node and go clients are notably less mature
> > than
> > > > the JVM clients, and that running Kafka in production means knowing
> > > enough
> > > > about the JVM and Zookeeper to handle that.
> > > >
> > > > Thanks!
> > > > Tom Crayford
> > > > Heroku Kafka
> > > >
> > > > >
> > > > > Thanks!
> > > > >
> > > > > - Oli
> > > >
> > > > >
> > > > > --
> > > > > - Oli
> > > > >
> > > > > Olivier Lalonde
> > > > > http://www.syskall.com
> > > >  <-- connect with me!
> > > > >
> > > >
> > >
> >
> >
> >
> >
> >
>
>
>
> --
> *Christian Posta*
> twitter: @christianposta
> http://www.christianposta.com/blog
> http://fabric8.io
>
>
>
>
>
>


-- 
*Christian Posta*
twitter: @christianposta
http://www.christianposta.com/blog
http://fabric8.io

Re: Kafka for event sourcing architecture

Posted by Radoslaw Gruchalski <ra...@gruchalski.com>.
Not as far as I'm aware. I'd be happy to contribute if there is a desire to have such feature. From experience with other projects, I know that without the initial pitch / discussion, it could be difficult to get such feature in. I can create a jira in the morning, no electricity again tonight :-/

Get Outlook for iOS




On Tue, May 17, 2016 at 4:53 PM -0700, "Christian Posta" <ch...@gmail.com> wrote:










+1 to your solution of log.cleanup.policy. Other brokers (ie, ActiveMQ)
have a feature like that.
Is there a JIRA for this?

On Tue, May 17, 2016 at 4:48 PM, Radoslaw Gruchalski 
wrote:

> I have described a cold storage solution for Kafka:
> https://medium.com/@rad_g/the-case-for-kafka-cold-storage-32929d0a57b2#.kf0jf8cwv.
> Also described it here a couple of times. Thd potential solution seems
> rather straightforward.
> Get Outlook for iOS
>
>     _____________________________
> From: Luke Steensen 
> Sent: Tuesday, May 17, 2016 11:22 pm
> Subject: Re: Kafka for event sourcing architecture
> To:  
>
>
> It's harder in Kafka because the unit of replication is an entire
> partition, not a single key/value pair. Partitions are large and constantly
> growing, where key/value pairs are typically much smaller and don't change
> in size. There would theoretically be no difference if you had one
> partition per key, but that's not practical. Instead, you end up trying to
> pick a number of partitions big enough that they'll each be a reasonable
> size for the foreseeable future but not so big that the cluster overhead is
> untenable. Even then the clock is ticking towards the day your biggest
> partition approaches the limit of storage available on a single machine.
>
> It's frustrating because, as you say, there would be enormous benefits to
> being able to access all data through the same system. Unfortunately, it
> seems too far away from Kafka's original use case to be practical.
>
>
> On Tue, May 17, 2016 at 12:32 PM, Daniel Schierbeck <
> dasch@zendesk.com.invalid> wrote:
>
> > I'm not sure why Kafka at least in theory cannot be used for infinite
> > retention – any replicated database system would need to have a new node
> > ingest all the data from failed node from its replicas. Surely this is no
> > different in S3 itself. Why is this harder to do in Kafka than in other
> > systems? The benefit of having just a single message log system would be
> > rather big.
> >
> > On Tue, May 17, 2016 at 4:44 AM Tom Crayford 
> wrote:
> >
> > > Hi Oli,
> > >
> > > Inline.
> > >
> > > On Tuesday, 17 May 2016, Olivier Lalonde  wrote:
> > >
> > > > Hi all,
> > > >
> > > > I am considering adopting an "event sourcing" architecture for a
> > system I
> > > > am developing and Kafka seems like a good choice of store for events.
> > > >
> > > > For those who aren't aware, this architecture style consists in
> storing
> > > all
> > > > state changes of the system as an ordered log of events and building
> > > > derivative views as needed for easier querying (using a SQL database
> > for
> > > > example). Those views must be completely derived from the event log
> > alone
> > > > so that the log effectively becomes a "single source of truth".
> > > >
> > > > I was wondering if anyone else is using Kafka for that purpose and
> more
> > > > specifically:
> > > >
> > > > 1) Can Kafka store messages permanently?
> > >
> > >
> > > No. Whilst you can tweak config and such to get a very long retention
> > > period, this doesn't work well with Kafka at all. Keeping data around
> > > forever has severe impacts on the operability of your cluster. For
> > example,
> > > if a machine fails, a replacement would have to catch up with vast
> > > quantities of data from its replicas. Currently we (Heroku Kafka)
> > restrict
> > > our customers to a maximum of 14 days of retention, because of all the
> > > operational headaches of more retention than that. Of course on your
> own
> > > cluster you *can* set it as high as you like, this is just an anecdotal
> > > experience thing from a team that runs thousands of clusters - infinite
> > > retention is an operational disaster waiting to happen.
> > >
> > > Whilst Kafka does have a replay mechanism, that should mostly be though
> > of
> > > as a mechanism for handling other system failures. E.g. If the database
> > you
> > > store indexed views is is down, Kafka's replay and retention mechanisms
> > > mean you're not losing data whilst restoring the availability of that
> > > database.
> > >
> > > What we typically suggest customers do when they ask about this use
> case
> > is
> > > to use Kafka as a messaging system, but use e.g. S3 as the long term
> > store.
> > > Kafka can help with batching writes up to S3 (see e.g. Pintrest's secor
> > > project), and act as a very high throughput, durable, replicated
> > messaging
> > > layer for communication. In this paradigm, when you want to replay, you
> > do
> > > so out of S3 until you've consumed the last offset there, then start
> > > replaying out of and catching up with the small amount of remaining
> data
> > in
> > > Kafka. Of course the replay logic there has to be hand rolled, as Kafka
> > and
> > > its clients have no knowledge of external stores.
> > >
> > > Another potential thing to look at is Kafka's compacted topic
> mechanism.
> > > With compacted topics, Kafka keeps the latest element for a given key,
> > > making it act a little more like a database table. Note that you still
> > have
> > > to consume by offset here - there's no "get the value for key Y
> > > operation". However, this assumes that your keyspace is still tractably
> > > small, and that you're ok with keeping only the latest value.
> Compaction
> > > completely overrides time based retention, so you have to "delete" keys
> > or
> > > have a bounded keyspace if you want to retain operational sanity with
> > > Kafka. I'd recommend reading the docs on compacted topics, they cover
> the
> > > use cases quite well.
> > >
> > >
> > >
> > > >
> > > > 2) Let's say I throw away my derived view and want to re-build it
> from
> > > > scratch, is it possible to consume messages from a topic from its
> very
> > > > first message and once it has caught up, listen for new messages like
> > it
> > > > would normally do?
> > >
> > >
> > > That's entirely possible, you can catch up from the first retained
> > message
> > > and then continue from there very easily. However, see above about
> > infinite
> > > retention.
> > >
> > >
> > >
> > > >
> > > > 2) Does it support transactions? Let's say I want to push 3 messages
> > > > atomically but the producer process crashes after sending only 2
> > > messages,
> > > > is it possible to "rollback" the first 2 messages (e.g. "all or
> > nothing"
> > > > semantics)?
> > >
> > >
> > > No. Kafka at the moment only supports "at least once" semantics, and
> > there
> > > are no cross broker transactions of any kind. Implementing such a thing
> > > would likely have huge negative impacts on the current performance
> > > characteristics of Kafka, which would be a issue for many users.
> > >
> > >
> > > >
> > > > 3) Does it support request/response style semantics or can they be
> > > > simulated? My system's primary interface with the outside world is an
> > > HTTP
> > > > API so it would be nice if I could publish an event and wait for all
> > the
> > > > internal services which need to process the event to be "done"
> > > > processing before returning a response.
> > >
> > >
> > >
> > > In theory that's possible - the producer can return the offset of the
> > > message produced, and you could check the latest offset of each
> consumer
> > in
> > > your web request handler.
> > >
> > > However, doing so is not going to work that well, unless you're ok with
> > > your web requests taking on the order of seconds to tens of seconds to
> > > fulfill. Kafka can do low latency messaging reasonably well, but
> > > coordinating the offsets of many consumers would likely have a huge
> > latency
> > > impact. Writing the code for it and getting it handling failure
> correctly
> > > would likely be a lot of work (there's nothing in any of the client
> > > libraries like this, because it is not a desirable or supported use
> > case).
> > >
> > > Instead I'd like to query *why* you need those semantics? What's the
> > issue
> > > with just producing a message and telling the user HTTP 200 and later
> > > consuming it.
> > >
> > >
> > >
> > > >
> > > > PS: I'm a Node.js/Go developer so when possible please avoid Java
> > centric
> > > > terminology.
> > >
> > >
> > > Please to note that the node and go clients are notably less mature
> than
> > > the JVM clients, and that running Kafka in production means knowing
> > enough
> > > about the JVM and Zookeeper to handle that.
> > >
> > > Thanks!
> > > Tom Crayford
> > > Heroku Kafka
> > >
> > > >
> > > > Thanks!
> > > >
> > > > - Oli
> > >
> > > >
> > > > --
> > > > - Oli
> > > >
> > > > Olivier Lalonde
> > > > http://www.syskall.com
> > >  <-- connect with me!
> > > >
> > >
> >
>
>
>
>
>



-- 
*Christian Posta*
twitter: @christianposta
http://www.christianposta.com/blog
http://fabric8.io






Re: Kafka for event sourcing architecture

Posted by Christian Posta <ch...@gmail.com>.
+1 to your solution of log.cleanup.policy. Other brokers (ie, ActiveMQ)
have a feature like that.
Is there a JIRA for this?

On Tue, May 17, 2016 at 4:48 PM, Radoslaw Gruchalski <ra...@gruchalski.com>
wrote:

> I have described a cold storage solution for Kafka:
> https://medium.com/@rad_g/the-case-for-kafka-cold-storage-32929d0a57b2#.kf0jf8cwv.
> Also described it here a couple of times. Thd potential solution seems
> rather straightforward.
> Get Outlook for iOS
>
>     _____________________________
> From: Luke Steensen <lu...@braintreepayments.com>
> Sent: Tuesday, May 17, 2016 11:22 pm
> Subject: Re: Kafka for event sourcing architecture
> To:  <us...@kafka.apache.org>
>
>
> It's harder in Kafka because the unit of replication is an entire
> partition, not a single key/value pair. Partitions are large and constantly
> growing, where key/value pairs are typically much smaller and don't change
> in size. There would theoretically be no difference if you had one
> partition per key, but that's not practical. Instead, you end up trying to
> pick a number of partitions big enough that they'll each be a reasonable
> size for the foreseeable future but not so big that the cluster overhead is
> untenable. Even then the clock is ticking towards the day your biggest
> partition approaches the limit of storage available on a single machine.
>
> It's frustrating because, as you say, there would be enormous benefits to
> being able to access all data through the same system. Unfortunately, it
> seems too far away from Kafka's original use case to be practical.
>
>
> On Tue, May 17, 2016 at 12:32 PM, Daniel Schierbeck <
> dasch@zendesk.com.invalid> wrote:
>
> > I'm not sure why Kafka at least in theory cannot be used for infinite
> > retention – any replicated database system would need to have a new node
> > ingest all the data from failed node from its replicas. Surely this is no
> > different in S3 itself. Why is this harder to do in Kafka than in other
> > systems? The benefit of having just a single message log system would be
> > rather big.
> >
> > On Tue, May 17, 2016 at 4:44 AM Tom Crayford <tc...@heroku.com>
> wrote:
> >
> > > Hi Oli,
> > >
> > > Inline.
> > >
> > > On Tuesday, 17 May 2016, Olivier Lalonde <ol...@gmail.com> wrote:
> > >
> > > > Hi all,
> > > >
> > > > I am considering adopting an "event sourcing" architecture for a
> > system I
> > > > am developing and Kafka seems like a good choice of store for events.
> > > >
> > > > For those who aren't aware, this architecture style consists in
> storing
> > > all
> > > > state changes of the system as an ordered log of events and building
> > > > derivative views as needed for easier querying (using a SQL database
> > for
> > > > example). Those views must be completely derived from the event log
> > alone
> > > > so that the log effectively becomes a "single source of truth".
> > > >
> > > > I was wondering if anyone else is using Kafka for that purpose and
> more
> > > > specifically:
> > > >
> > > > 1) Can Kafka store messages permanently?
> > >
> > >
> > > No. Whilst you can tweak config and such to get a very long retention
> > > period, this doesn't work well with Kafka at all. Keeping data around
> > > forever has severe impacts on the operability of your cluster. For
> > example,
> > > if a machine fails, a replacement would have to catch up with vast
> > > quantities of data from its replicas. Currently we (Heroku Kafka)
> > restrict
> > > our customers to a maximum of 14 days of retention, because of all the
> > > operational headaches of more retention than that. Of course on your
> own
> > > cluster you *can* set it as high as you like, this is just an anecdotal
> > > experience thing from a team that runs thousands of clusters - infinite
> > > retention is an operational disaster waiting to happen.
> > >
> > > Whilst Kafka does have a replay mechanism, that should mostly be though
> > of
> > > as a mechanism for handling other system failures. E.g. If the database
> > you
> > > store indexed views is is down, Kafka's replay and retention mechanisms
> > > mean you're not losing data whilst restoring the availability of that
> > > database.
> > >
> > > What we typically suggest customers do when they ask about this use
> case
> > is
> > > to use Kafka as a messaging system, but use e.g. S3 as the long term
> > store.
> > > Kafka can help with batching writes up to S3 (see e.g. Pintrest's secor
> > > project), and act as a very high throughput, durable, replicated
> > messaging
> > > layer for communication. In this paradigm, when you want to replay, you
> > do
> > > so out of S3 until you've consumed the last offset there, then start
> > > replaying out of and catching up with the small amount of remaining
> data
> > in
> > > Kafka. Of course the replay logic there has to be hand rolled, as Kafka
> > and
> > > its clients have no knowledge of external stores.
> > >
> > > Another potential thing to look at is Kafka's compacted topic
> mechanism.
> > > With compacted topics, Kafka keeps the latest element for a given key,
> > > making it act a little more like a database table. Note that you still
> > have
> > > to consume by offset here - there's no "get the value for key Y
> > > operation". However, this assumes that your keyspace is still tractably
> > > small, and that you're ok with keeping only the latest value.
> Compaction
> > > completely overrides time based retention, so you have to "delete" keys
> > or
> > > have a bounded keyspace if you want to retain operational sanity with
> > > Kafka. I'd recommend reading the docs on compacted topics, they cover
> the
> > > use cases quite well.
> > >
> > >
> > >
> > > >
> > > > 2) Let's say I throw away my derived view and want to re-build it
> from
> > > > scratch, is it possible to consume messages from a topic from its
> very
> > > > first message and once it has caught up, listen for new messages like
> > it
> > > > would normally do?
> > >
> > >
> > > That's entirely possible, you can catch up from the first retained
> > message
> > > and then continue from there very easily. However, see above about
> > infinite
> > > retention.
> > >
> > >
> > >
> > > >
> > > > 2) Does it support transactions? Let's say I want to push 3 messages
> > > > atomically but the producer process crashes after sending only 2
> > > messages,
> > > > is it possible to "rollback" the first 2 messages (e.g. "all or
> > nothing"
> > > > semantics)?
> > >
> > >
> > > No. Kafka at the moment only supports "at least once" semantics, and
> > there
> > > are no cross broker transactions of any kind. Implementing such a thing
> > > would likely have huge negative impacts on the current performance
> > > characteristics of Kafka, which would be a issue for many users.
> > >
> > >
> > > >
> > > > 3) Does it support request/response style semantics or can they be
> > > > simulated? My system's primary interface with the outside world is an
> > > HTTP
> > > > API so it would be nice if I could publish an event and wait for all
> > the
> > > > internal services which need to process the event to be "done"
> > > > processing before returning a response.
> > >
> > >
> > >
> > > In theory that's possible - the producer can return the offset of the
> > > message produced, and you could check the latest offset of each
> consumer
> > in
> > > your web request handler.
> > >
> > > However, doing so is not going to work that well, unless you're ok with
> > > your web requests taking on the order of seconds to tens of seconds to
> > > fulfill. Kafka can do low latency messaging reasonably well, but
> > > coordinating the offsets of many consumers would likely have a huge
> > latency
> > > impact. Writing the code for it and getting it handling failure
> correctly
> > > would likely be a lot of work (there's nothing in any of the client
> > > libraries like this, because it is not a desirable or supported use
> > case).
> > >
> > > Instead I'd like to query *why* you need those semantics? What's the
> > issue
> > > with just producing a message and telling the user HTTP 200 and later
> > > consuming it.
> > >
> > >
> > >
> > > >
> > > > PS: I'm a Node.js/Go developer so when possible please avoid Java
> > centric
> > > > terminology.
> > >
> > >
> > > Please to note that the node and go clients are notably less mature
> than
> > > the JVM clients, and that running Kafka in production means knowing
> > enough
> > > about the JVM and Zookeeper to handle that.
> > >
> > > Thanks!
> > > Tom Crayford
> > > Heroku Kafka
> > >
> > > >
> > > > Thanks!
> > > >
> > > > - Oli
> > >
> > > >
> > > > --
> > > > - Oli
> > > >
> > > > Olivier Lalonde
> > > > http://www.syskall.com
> > > <http://www.syskall.com> <-- connect with me!
> > > >
> > >
> >
>
>
>
>
>



-- 
*Christian Posta*
twitter: @christianposta
http://www.christianposta.com/blog
http://fabric8.io

Re: Kafka for event sourcing architecture

Posted by Radoslaw Gruchalski <ra...@gruchalski.com>.
I have described a cold storage solution for Kafka: https://medium.com/@rad_g/the-case-for-kafka-cold-storage-32929d0a57b2#.kf0jf8cwv. Also described it here a couple of times. Thd potential solution seems rather straightforward.
Get Outlook for iOS

    _____________________________
From: Luke Steensen <lu...@braintreepayments.com>
Sent: Tuesday, May 17, 2016 11:22 pm
Subject: Re: Kafka for event sourcing architecture
To:  <us...@kafka.apache.org>


It's harder in Kafka because the unit of replication is an entire
partition, not a single key/value pair. Partitions are large and constantly
growing, where key/value pairs are typically much smaller and don't change
in size. There would theoretically be no difference if you had one
partition per key, but that's not practical. Instead, you end up trying to
pick a number of partitions big enough that they'll each be a reasonable
size for the foreseeable future but not so big that the cluster overhead is
untenable. Even then the clock is ticking towards the day your biggest
partition approaches the limit of storage available on a single machine.

It's frustrating because, as you say, there would be enormous benefits to
being able to access all data through the same system. Unfortunately, it
seems too far away from Kafka's original use case to be practical.


On Tue, May 17, 2016 at 12:32 PM, Daniel Schierbeck <
dasch@zendesk.com.invalid> wrote:

> I'm not sure why Kafka at least in theory cannot be used for infinite
> retention – any replicated database system would need to have a new node
> ingest all the data from failed node from its replicas. Surely this is no
> different in S3 itself. Why is this harder to do in Kafka than in other
> systems? The benefit of having just a single message log system would be
> rather big.
>
> On Tue, May 17, 2016 at 4:44 AM Tom Crayford <tc...@heroku.com> wrote:
>
> > Hi Oli,
> >
> > Inline.
> >
> > On Tuesday, 17 May 2016, Olivier Lalonde <ol...@gmail.com> wrote:
> >
> > > Hi all,
> > >
> > > I am considering adopting an "event sourcing" architecture for a
> system I
> > > am developing and Kafka seems like a good choice of store for events.
> > >
> > > For those who aren't aware, this architecture style consists in storing
> > all
> > > state changes of the system as an ordered log of events and building
> > > derivative views as needed for easier querying (using a SQL database
> for
> > > example). Those views must be completely derived from the event log
> alone
> > > so that the log effectively becomes a "single source of truth".
> > >
> > > I was wondering if anyone else is using Kafka for that purpose and more
> > > specifically:
> > >
> > > 1) Can Kafka store messages permanently?
> >
> >
> > No. Whilst you can tweak config and such to get a very long retention
> > period, this doesn't work well with Kafka at all. Keeping data around
> > forever has severe impacts on the operability of your cluster. For
> example,
> > if a machine fails, a replacement would have to catch up with vast
> > quantities of data from its replicas. Currently we (Heroku Kafka)
> restrict
> > our customers to a maximum of 14 days of retention, because of all the
> > operational headaches of more retention than that. Of course on your own
> > cluster you *can* set it as high as you like, this is just an anecdotal
> > experience thing from a team that runs thousands of clusters - infinite
> > retention is an operational disaster waiting to happen.
> >
> > Whilst Kafka does have a replay mechanism, that should mostly be though
> of
> > as a mechanism for handling other system failures. E.g. If the database
> you
> > store indexed views is is down, Kafka's replay and retention mechanisms
> > mean you're not losing data whilst restoring the availability of that
> > database.
> >
> > What we typically suggest customers do when they ask about this use case
> is
> > to use Kafka as a messaging system, but use e.g. S3 as the long term
> store.
> > Kafka can help with batching writes up to S3 (see e.g. Pintrest's secor
> > project), and act as a very high throughput, durable, replicated
> messaging
> > layer for communication. In this paradigm, when you want to replay, you
> do
> > so out of S3 until you've consumed the last offset there, then start
> > replaying out of and catching up with the small amount of remaining data
> in
> > Kafka. Of course the replay logic there has to be hand rolled, as Kafka
> and
> > its clients have no knowledge of external stores.
> >
> > Another potential thing to look at is Kafka's compacted topic mechanism.
> > With compacted topics, Kafka keeps the latest element for a given key,
> > making it act a little more like a database table. Note that you still
> have
> > to consume by offset here - there's no "get the value for key Y
> > operation". However, this assumes that your keyspace is still tractably
> > small, and that you're ok with keeping only the latest value. Compaction
> > completely overrides time based retention, so you have to "delete" keys
> or
> > have a bounded keyspace if you want to retain operational sanity with
> > Kafka. I'd recommend reading the docs on compacted topics, they cover the
> > use cases quite well.
> >
> >
> >
> > >
> > > 2) Let's say I throw away my derived view and want to re-build it from
> > > scratch, is it possible to consume messages from a topic from its very
> > > first message and once it has caught up, listen for new messages like
> it
> > > would normally do?
> >
> >
> > That's entirely possible, you can catch up from the first retained
> message
> > and then continue from there very easily. However, see above about
> infinite
> > retention.
> >
> >
> >
> > >
> > > 2) Does it support transactions? Let's say I want to push 3 messages
> > > atomically but the producer process crashes after sending only 2
> > messages,
> > > is it possible to "rollback" the first 2 messages (e.g. "all or
> nothing"
> > > semantics)?
> >
> >
> > No. Kafka at the moment only supports "at least once" semantics, and
> there
> > are no cross broker transactions of any kind. Implementing such a thing
> > would likely have huge negative impacts on the current performance
> > characteristics of Kafka, which would be a issue for many users.
> >
> >
> > >
> > > 3) Does it support request/response style semantics or can they be
> > > simulated? My system's primary interface with the outside world is an
> > HTTP
> > > API so it would be nice if I could publish an event and wait for all
> the
> > > internal services which need to process the event to be "done"
> > > processing before returning a response.
> >
> >
> >
> > In theory that's possible - the producer can return the offset of the
> > message produced, and you could check the latest offset of each consumer
> in
> > your web request handler.
> >
> > However, doing so is not going to work that well, unless you're ok with
> > your web requests taking on the order of seconds to tens of seconds to
> > fulfill. Kafka can do low latency messaging reasonably well, but
> > coordinating the offsets of many consumers would likely have a huge
> latency
> > impact. Writing the code for it and getting it handling failure correctly
> > would likely be a lot of work (there's nothing in any of the client
> > libraries like this, because it is not a desirable or supported use
> case).
> >
> > Instead I'd like to query *why* you need those semantics? What's the
> issue
> > with just producing a message and telling the user HTTP 200 and later
> > consuming it.
> >
> >
> >
> > >
> > > PS: I'm a Node.js/Go developer so when possible please avoid Java
> centric
> > > terminology.
> >
> >
> > Please to note that the node and go clients are notably less mature than
> > the JVM clients, and that running Kafka in production means knowing
> enough
> > about the JVM and Zookeeper to handle that.
> >
> > Thanks!
> > Tom Crayford
> > Heroku Kafka
> >
> > >
> > > Thanks!
> > >
> > > - Oli
> >
> > >
> > > --
> > > - Oli
> > >
> > > Olivier Lalonde
> > > http://www.syskall.com
> > <http://www.syskall.com> <-- connect with me!
> > >
> >
>



  

Re: Kafka for event sourcing architecture

Posted by Luke Steensen <lu...@braintreepayments.com>.
It's harder in Kafka because the unit of replication is an entire
partition, not a single key/value pair. Partitions are large and constantly
growing, where key/value pairs are typically much smaller and don't change
in size. There would theoretically be no difference if you had one
partition per key, but that's not practical. Instead, you end up trying to
pick a number of partitions big enough that they'll each be a reasonable
size for the foreseeable future but not so big that the cluster overhead is
untenable. Even then the clock is ticking towards the day your biggest
partition approaches the limit of storage available on a single machine.

It's frustrating because, as you say, there would be enormous benefits to
being able to access all data through the same system. Unfortunately, it
seems too far away from Kafka's original use case to be practical.


On Tue, May 17, 2016 at 12:32 PM, Daniel Schierbeck <
dasch@zendesk.com.invalid> wrote:

> I'm not sure why Kafka at least in theory cannot be used for infinite
> retention – any replicated database system would need to have a new node
> ingest all the data from failed node from its replicas. Surely this is no
> different in S3 itself. Why is this harder to do in Kafka than in other
> systems? The benefit of having just a single message log system would be
> rather big.
>
> On Tue, May 17, 2016 at 4:44 AM Tom Crayford <tc...@heroku.com> wrote:
>
> > Hi Oli,
> >
> > Inline.
> >
> > On Tuesday, 17 May 2016, Olivier Lalonde <ol...@gmail.com> wrote:
> >
> > > Hi all,
> > >
> > > I am considering adopting an "event sourcing" architecture for a
> system I
> > > am developing and Kafka seems like a good choice of store for events.
> > >
> > > For those who aren't aware, this architecture style consists in storing
> > all
> > > state changes of the system as an ordered log of events and building
> > > derivative views as needed for easier querying (using a SQL database
> for
> > > example). Those views must be completely derived from the event log
> alone
> > > so that the log effectively becomes a "single source of truth".
> > >
> > > I was wondering if anyone else is using Kafka for that purpose and more
> > > specifically:
> > >
> > > 1) Can Kafka store messages permanently?
> >
> >
> > No. Whilst you can tweak config and such to get a very long retention
> > period, this doesn't work well with Kafka at all. Keeping data around
> > forever has severe impacts on the operability of your cluster. For
> example,
> > if a machine fails, a replacement would have to catch up with vast
> > quantities of data from its replicas. Currently we (Heroku Kafka)
> restrict
> > our customers to a maximum of 14 days of retention, because of all the
> > operational headaches of more retention than that. Of course on your own
> > cluster you *can* set it as high as you like, this is just an anecdotal
> > experience thing from a team that runs thousands of clusters - infinite
> > retention is an operational disaster waiting to happen.
> >
> > Whilst Kafka does have a replay mechanism, that should mostly be though
> of
> > as a mechanism for handling other system failures. E.g. If the database
> you
> > store indexed views is is down, Kafka's replay and retention mechanisms
> > mean you're not losing data whilst restoring the availability of that
> > database.
> >
> > What we typically suggest customers do when they ask about this use case
> is
> > to use Kafka as a messaging system, but use e.g. S3 as the long term
> store.
> > Kafka can help with batching writes up to S3 (see e.g. Pintrest's secor
> > project), and act as a very high throughput, durable, replicated
> messaging
> > layer for communication. In this paradigm, when you want to replay, you
> do
> > so out of S3 until you've consumed the last offset there, then start
> > replaying out of and catching up with the small amount of remaining data
> in
> > Kafka. Of course the replay logic there has to be hand rolled, as Kafka
> and
> > its clients have no knowledge of external stores.
> >
> > Another potential thing to look at is Kafka's compacted topic mechanism.
> > With compacted topics, Kafka keeps the latest element for a given key,
> > making it act a little more like a database table. Note that you still
> have
> > to consume by offset here - there's no "get the value for key Y
> > operation". However, this assumes that your keyspace is still tractably
> > small, and that you're ok with keeping only the latest value. Compaction
> > completely overrides time based retention, so you have to "delete" keys
> or
> > have a bounded keyspace if you want to retain operational sanity with
> > Kafka. I'd recommend reading the docs on compacted topics, they cover the
> > use cases quite well.
> >
> >
> >
> > >
> > > 2) Let's say I throw away my derived view and want to re-build it from
> > > scratch, is it possible to consume messages from a topic from its very
> > > first message and once it has caught up, listen for new messages like
> it
> > > would normally do?
> >
> >
> > That's entirely possible, you can catch up from the first retained
> message
> > and then continue from there very easily. However, see above about
> infinite
> > retention.
> >
> >
> >
> > >
> > > 2) Does it support transactions? Let's say I want to push 3 messages
> > > atomically but the producer process crashes after sending only 2
> > messages,
> > > is it possible to "rollback" the first 2 messages (e.g. "all or
> nothing"
> > > semantics)?
> >
> >
> > No. Kafka at the moment only supports "at least once" semantics, and
> there
> > are no cross broker transactions of any kind. Implementing such a thing
> > would likely have huge negative impacts on the current performance
> > characteristics of Kafka, which would be a issue for many users.
> >
> >
> > >
> > > 3) Does it support request/response style semantics or can they be
> > > simulated? My system's primary interface with the outside world is an
> > HTTP
> > > API so it would be nice if I could publish an event and wait for all
> the
> > > internal services which need to process the event to be "done"
> > > processing before returning a response.
> >
> >
> >
> > In theory that's possible - the producer can return the offset of the
> > message produced, and you could check the latest offset of each consumer
> in
> > your web request handler.
> >
> > However, doing so is not going to work that well, unless you're ok with
> > your web requests taking on the order of seconds to tens of seconds to
> > fulfill. Kafka can do low latency messaging reasonably well, but
> > coordinating the offsets of many consumers would likely have a huge
> latency
> > impact. Writing the code for it and getting it handling failure correctly
> > would likely be a lot of work (there's nothing in any of the client
> > libraries like this, because it is not a desirable or supported use
> case).
> >
> > Instead I'd like to query *why* you need those semantics? What's the
> issue
> > with just producing a message and telling the user HTTP 200 and later
> > consuming it.
> >
> >
> >
> > >
> > > PS: I'm a Node.js/Go developer so when possible please avoid Java
> centric
> > > terminology.
> >
> >
> > Please to note that the node and go clients are notably less mature than
> > the JVM clients, and that running Kafka in production means knowing
> enough
> > about the JVM and Zookeeper to handle that.
> >
> > Thanks!
> > Tom Crayford
> > Heroku Kafka
> >
> > >
> > > Thanks!
> > >
> > > - Oli
> >
> > >
> > > --
> > > - Oli
> > >
> > > Olivier Lalonde
> > > http://www.syskall.com
> > <http://www.syskall.com> <-- connect with me!
> > >
> >
>

Re: Kafka for event sourcing architecture

Posted by Daniel Schierbeck <da...@zendesk.com.INVALID>.
I'm not sure why Kafka at least in theory cannot be used for infinite
retention – any replicated database system would need to have a new node
ingest all the data from failed node from its replicas. Surely this is no
different in S3 itself. Why is this harder to do in Kafka than in other
systems? The benefit of having just a single message log system would be
rather big.

On Tue, May 17, 2016 at 4:44 AM Tom Crayford <tc...@heroku.com> wrote:

> Hi Oli,
>
> Inline.
>
> On Tuesday, 17 May 2016, Olivier Lalonde <ol...@gmail.com> wrote:
>
> > Hi all,
> >
> > I am considering adopting an "event sourcing" architecture for a system I
> > am developing and Kafka seems like a good choice of store for events.
> >
> > For those who aren't aware, this architecture style consists in storing
> all
> > state changes of the system as an ordered log of events and building
> > derivative views as needed for easier querying (using a SQL database for
> > example). Those views must be completely derived from the event log alone
> > so that the log effectively becomes a "single source of truth".
> >
> > I was wondering if anyone else is using Kafka for that purpose and more
> > specifically:
> >
> > 1) Can Kafka store messages permanently?
>
>
> No. Whilst you can tweak config and such to get a very long retention
> period, this doesn't work well with Kafka at all. Keeping data around
> forever has severe impacts on the operability of your cluster. For example,
> if a machine fails, a replacement would have to catch up with vast
> quantities of data from its replicas. Currently we (Heroku Kafka) restrict
> our customers to a maximum of 14 days of retention, because of all the
> operational headaches of more retention than that. Of course on your own
> cluster you *can* set it as high as you like, this is just an anecdotal
> experience thing from a team that runs thousands of clusters - infinite
> retention is an operational disaster waiting to happen.
>
> Whilst Kafka does have a replay mechanism, that should mostly be though of
> as a mechanism for handling other system failures. E.g. If the database you
> store indexed views is is down, Kafka's replay and retention mechanisms
> mean you're not losing data whilst restoring the availability of that
> database.
>
> What we typically suggest customers do when they ask about this use case is
> to use Kafka as a messaging system, but use e.g. S3 as the long term store.
> Kafka can help with batching writes up to S3 (see e.g. Pintrest's secor
> project), and act as a very high throughput, durable, replicated messaging
> layer for communication. In this paradigm, when you want to replay, you do
> so out of S3 until you've consumed the last offset there, then start
> replaying out of and catching up with the small amount of remaining data in
> Kafka. Of course the replay logic there has to be hand rolled, as Kafka and
> its clients have no knowledge of external stores.
>
> Another potential thing to look at is Kafka's compacted topic mechanism.
> With compacted topics, Kafka keeps the latest element for a given key,
> making it act a little more like a database table. Note that you still have
> to consume by offset here - there's no "get the value for key Y
> operation". However, this assumes that your keyspace is still tractably
> small, and that you're ok with keeping only the latest value. Compaction
> completely overrides time based retention, so you have to "delete" keys or
> have a bounded keyspace if you want to retain operational sanity with
> Kafka. I'd recommend reading the docs on compacted topics, they cover the
> use cases quite well.
>
>
>
> >
> > 2) Let's say I throw away my derived view and want to re-build it from
> > scratch, is it possible to consume messages from a topic from its very
> > first message and once it has caught up, listen for new messages like it
> > would normally do?
>
>
> That's entirely possible, you can catch up from the first retained message
> and then continue from there very easily. However, see above about infinite
> retention.
>
>
>
> >
> > 2) Does it support transactions? Let's say I want to push 3 messages
> > atomically but the producer process crashes after sending only 2
> messages,
> > is it possible to "rollback" the first 2 messages (e.g. "all or nothing"
> > semantics)?
>
>
> No. Kafka at the moment only supports "at least once" semantics, and there
> are no cross broker transactions of any kind. Implementing such a thing
> would likely have huge negative impacts on the current performance
> characteristics of Kafka, which would be a issue for many users.
>
>
> >
> > 3) Does it support request/response style semantics or can they be
> > simulated? My system's primary interface with the outside world is an
> HTTP
> > API so it would be nice if I could publish an event and wait for all the
> > internal services which need to process the event to be "done"
> > processing before returning a response.
>
>
>
> In theory that's possible - the producer can return the offset of the
> message produced, and you could check the latest offset of each consumer in
> your web request handler.
>
> However, doing so is not going to work that well, unless you're ok with
> your web requests taking on the order of seconds to tens of seconds to
> fulfill. Kafka can do low latency messaging reasonably well, but
> coordinating the offsets of many consumers would likely have a huge latency
> impact. Writing the code for it and getting it handling failure correctly
> would likely be a lot of work (there's nothing in any of the client
> libraries like this, because it is not a desirable or supported use case).
>
> Instead I'd like to query *why* you need those semantics? What's the issue
> with just producing a message and telling the user HTTP 200 and later
> consuming it.
>
>
>
> >
> > PS: I'm a Node.js/Go developer so when possible please avoid Java centric
> > terminology.
>
>
> Please to note that the node and go clients are notably less mature than
> the JVM clients, and that running Kafka in production means knowing enough
> about the JVM and Zookeeper to handle that.
>
> Thanks!
> Tom Crayford
> Heroku Kafka
>
> >
> > Thanks!
> >
> > - Oli
>
> >
> > --
> > - Oli
> >
> > Olivier Lalonde
> > http://www.syskall.com
> <http://www.syskall.com> <-- connect with me!
> >
>

Re: Kafka for event sourcing architecture

Posted by Tom Crayford <tc...@heroku.com>.
Hi Oli,

Inline.

On Tuesday, 17 May 2016, Olivier Lalonde <ol...@gmail.com> wrote:

> Hi all,
>
> I am considering adopting an "event sourcing" architecture for a system I
> am developing and Kafka seems like a good choice of store for events.
>
> For those who aren't aware, this architecture style consists in storing all
> state changes of the system as an ordered log of events and building
> derivative views as needed for easier querying (using a SQL database for
> example). Those views must be completely derived from the event log alone
> so that the log effectively becomes a "single source of truth".
>
> I was wondering if anyone else is using Kafka for that purpose and more
> specifically:
>
> 1) Can Kafka store messages permanently?


No. Whilst you can tweak config and such to get a very long retention
period, this doesn't work well with Kafka at all. Keeping data around
forever has severe impacts on the operability of your cluster. For example,
if a machine fails, a replacement would have to catch up with vast
quantities of data from its replicas. Currently we (Heroku Kafka) restrict
our customers to a maximum of 14 days of retention, because of all the
operational headaches of more retention than that. Of course on your own
cluster you *can* set it as high as you like, this is just an anecdotal
experience thing from a team that runs thousands of clusters - infinite
retention is an operational disaster waiting to happen.

Whilst Kafka does have a replay mechanism, that should mostly be though of
as a mechanism for handling other system failures. E.g. If the database you
store indexed views is is down, Kafka's replay and retention mechanisms
mean you're not losing data whilst restoring the availability of that
database.

What we typically suggest customers do when they ask about this use case is
to use Kafka as a messaging system, but use e.g. S3 as the long term store.
Kafka can help with batching writes up to S3 (see e.g. Pintrest's secor
project), and act as a very high throughput, durable, replicated messaging
layer for communication. In this paradigm, when you want to replay, you do
so out of S3 until you've consumed the last offset there, then start
replaying out of and catching up with the small amount of remaining data in
Kafka. Of course the replay logic there has to be hand rolled, as Kafka and
its clients have no knowledge of external stores.

Another potential thing to look at is Kafka's compacted topic mechanism.
With compacted topics, Kafka keeps the latest element for a given key,
making it act a little more like a database table. Note that you still have
to consume by offset here - there's no "get the value for key Y
operation". However, this assumes that your keyspace is still tractably
small, and that you're ok with keeping only the latest value. Compaction
completely overrides time based retention, so you have to "delete" keys or
have a bounded keyspace if you want to retain operational sanity with
Kafka. I'd recommend reading the docs on compacted topics, they cover the
use cases quite well.



>
> 2) Let's say I throw away my derived view and want to re-build it from
> scratch, is it possible to consume messages from a topic from its very
> first message and once it has caught up, listen for new messages like it
> would normally do?


That's entirely possible, you can catch up from the first retained message
and then continue from there very easily. However, see above about infinite
retention.



>
> 2) Does it support transactions? Let's say I want to push 3 messages
> atomically but the producer process crashes after sending only 2 messages,
> is it possible to "rollback" the first 2 messages (e.g. "all or nothing"
> semantics)?


No. Kafka at the moment only supports "at least once" semantics, and there
are no cross broker transactions of any kind. Implementing such a thing
would likely have huge negative impacts on the current performance
characteristics of Kafka, which would be a issue for many users.


>
> 3) Does it support request/response style semantics or can they be
> simulated? My system's primary interface with the outside world is an HTTP
> API so it would be nice if I could publish an event and wait for all the
> internal services which need to process the event to be "done"
> processing before returning a response.



In theory that's possible - the producer can return the offset of the
message produced, and you could check the latest offset of each consumer in
your web request handler.

However, doing so is not going to work that well, unless you're ok with
your web requests taking on the order of seconds to tens of seconds to
fulfill. Kafka can do low latency messaging reasonably well, but
coordinating the offsets of many consumers would likely have a huge latency
impact. Writing the code for it and getting it handling failure correctly
would likely be a lot of work (there's nothing in any of the client
libraries like this, because it is not a desirable or supported use case).

Instead I'd like to query *why* you need those semantics? What's the issue
with just producing a message and telling the user HTTP 200 and later
consuming it.



>
> PS: I'm a Node.js/Go developer so when possible please avoid Java centric
> terminology.


Please to note that the node and go clients are notably less mature than
the JVM clients, and that running Kafka in production means knowing enough
about the JVM and Zookeeper to handle that.

Thanks!
Tom Crayford
Heroku Kafka

>
> Thanks!
>
> - Oli
>
> --
> - Oli
>
> Olivier Lalonde
> http://www.syskall.com <-- connect with me!
>

Re: Kafka for event sourcing architecture

Posted by Radoslaw Gruchalski <ra...@gruchalski.com>.
I have created the JIRA: https://issues.apache.org/jira/browse/KAFKA-3726
–  
Best regards,

Radek Gruchalski

radek@gruchalski.com
de.linkedin.com/in/radgruchalski

Confidentiality:
This communication is intended for the above-named person and may be confidential and/or legally privileged.
If it has come to you in error you must take no action based on it, nor must you copy or show it to anyone; please delete/destroy and inform the sender immediately.

On May 18, 2016 at 3:57:43 PM, Radoslaw Gruchalski (radek@gruchalski.com) wrote:

Hi Tom,

There is, indeed, the problem with replication in case of the leader change for the partition.
Hence, I think the best, best approach would to have Kafka emit events in case of:

- partition leader change
- offset file to be cleaned up

This still leaves a lot of work for the ops people to actually implement the cold storage but it makes it at least possible. From there on, it’s all about tooling.
I’ve got electricity back, I’m going to prepare a JIRA.
–  
Best regards,

Radek Gruchalski

radek@gruchalski.com
de.linkedin.com/in/radgruchalski

Confidentiality:
This communication is intended for the above-named person and may be confidential and/or legally privileged.
If it has come to you in error you must take no action based on it, nor must you copy or show it to anyone; please delete/destroy and inform the sender immediately.

On May 18, 2016 at 3:34:30 PM, Tom Crayford (tcrayford@heroku.com) wrote:

The issue I have with that log.cleanup.policy approach is how it impacts
with replication. Different replicas often have different sets of segment
files. There are effectively two options then:
1. All replicas upload all their segments. This has issues with storage
space, but is easy to implement. It's hard to reason about from a user's
perspective though - what happens when the replicas for a partition are
reassigned? Do we upload under some namespace by broker id? That'd mean
reassigning replicas will change where things get stored in S3
2. Only the leader uploads it's segments. This presents a totally different
issue, as different brokers have different sets of segment files. To recap
a second, segment files contain a certain set of offsets, e.g. 0-100000
might be in one file, then 100001-200000 in another. However, there's no
consistency of offset overlap between replicas. This means that Kafka's now
in charge of tracking which offset it's deleted to (in some replicated
storage), and it has to truncate files before sending them to the archive
command. Alternatively, another option is to allow multiple overlaps in
storage. This presents confusing behaviour for users when the leader
changes, as there will now be overlaps in storage. Also worth thinking
about how a cold storage proposal works with unclean leader election.

Another point I take issue with is the fact that now we're using Kafka's on
disk storage format as a long term API thing for the cold storage of data.
Clients *have* to integrate against the broker code for reading on disk
storage (which only works for JVM clients right now, furthering the already
huge amount of work it takes to support non JVM client libraries). Right
now that code *and* the storage format isn't public at all and is subject
to change (aside from normal backwards compatibility concerns with on disk
storage). With a current "a separate consumer archives to cold storage"
approach the consumer gets to specify whatever format it likes, control
batching in a way that makes sense for your cold storage system of choice
(some may prefer 1GB batches, some may prefer 100MB batches etc). Doing
this in the archiving command would be possible, but does put additional
strain on the broker machine and complicates the archiving command
significantly.

Furthermore, that rough cold storage proposal, as outlined still requires
clients to do large amounts of custom work to consume from the beginning of
time. I think avoiding much of that custom work was much of the point of
"why can't Kafka do infinite retention" thing. I can imagine a nicer to use
thing in which Kafka, upon receiving an earlier offset than the beginning
of it's queue could *also* restore the segments from cold storage one by
one, but that seems extremely tricky to implement, if much nicer in
practice.

Overall, any cold storage proposal seems like a drastic change and
complication of the role of Kafka in a system. This makes it harder to
implement and harder to run in production. It also makes it more confusing
to use as a customer (even if you have an ops team or a PaaS offering
running it for you), because now you're using a long term data store, not
an ephemeral streaming system.

I think Kafka is a great fit in an event-sourced architecture, but not as
the long term cold storage, just the messaging layer. For long term low
volume event storage, a traditional database often works very well anyway
(the control plane that powers Heroku Kafka and Heroku Postgres does
something like this with Postgres, and it's worked extremely well for the
8+ years the control plane has been running). For high volume, a consumer
archiving to S3 (or other long term storage) is relatively simple to
implement (or you can use secor which is an off the shelf dropin for most
folk).

On Wed, May 18, 2016 at 12:19 PM, Christian Posta <christian.posta@gmail.com
> wrote:

> So Kafka is a fine solution as part of an event-sourced story. It's not a
> simple solution, but it fits.
>
> Kakfa can store data for a long time and you shouldn't discount this,
> however, using it as the primary long-term data store might not be a good
> fit if we're talking storing raw events for years and years. I think
> someone in another thread mentioned moving these raw events to S3 or some
> object store which is probably a good idea. Kafka can store the "head" of
> the raw event stream as well as "snapshots" in time of the raw event stream
> that your applications can consume. If a raw event stream ends up super
> big, it may be impractical for an application to consume it from he
> beginning of time to recreate its datastore anyway; thus
> snapshots/aggregate snapshots help with this. Years and years of raw events
> may be useful for batch analytics (spark/hadoop) as well.
>
> In terms of an event store, I quite like the idea of using raw events to
> generate the projections/materialized views of domain objects AND using
> events within those domain objects to generate new raw events. This can be
> done nicely with Kafka feeding a DDD aggregate root --> traditional
> database --> Kafka. You can use CDC style solutions to capture the database
> journal log and publish events that way. Things like Kafka Connect become
> really handy for a solution like this as well as Martin K's Bottled Water
> project and our Debezium project: http://debezium.io ... i've got a
> blog+video demo of all of this coming soon!
>
> On Wed, May 18, 2016 at 1:15 AM, Olivier Lalonde <ol...@gmail.com>
> wrote:
>
> > Dave:
> >
> > Thanks for the suggestion, Bookkeeper looks interesting. I assume you
> meant
> > "more high-level interface"?
> >
> > Chris:
> >
> > Thanks Chris, I actually came across a few of your talks and articles
> when
> > researching this style of architecture (along with stuff by Greg Young
> and
> > Martin Kleppmann) and really excited to see you pop in this thread.
> >
> > I understand Kafka is fairly low level for what I really need. I'm not
> > really convinced I will need random access to the event store though,
> this
> > seems to be a specific style of event sourcing architecture (with roots
> > stemming from DDD?) where the application state is all kept in memory?
> >
> > My idea was to use a PostgreSQL to "cache" my state and do queries from
> > (and possibly other types of databases in the future as needed). To build
> > the PostgreSQL database or add new derived state "caches" (Greg Young
> calls
> > those "projections" I believe) I would just replay the event stream from
> > event 0 with some glue code to handle the new event => database logic. It
> > keeps things simple though I suppose it could be slow when my event
> stream
> > gets really big (could add snapshots as a concept eventually).
> >
> > I read a bit about eventuate.io but it wasn't clear to me whether this
> was
> > an application framework or a server (open source? commercial?).
> >
> > One thing that doesn't help is that we're primarily a Node.js shop and
> all
> > the information, tooling, examples and terminology is heavily geared
> > towards JVM developers. I found this great talk by Stefan Kutko
> > https://www.youtube.com/watch?v=X_VHWQa1k0k which describes a Node.js
> > based
> > event sourced architecture but it's a bit short on implementation
> details.
> >
> > Abhaya:
> >
> > Also curious to hear what others have to say about this. What I'm trying
> to
> > achieve is to have a single unified event store from which all other data
> > stores are derived but I'm still unsure whether Kafka is the right
> choice.
> > I also believe that a lot of people use Kafka primarily as a message
> queue
> > and keep track of CRUD style state in a more traditional ACID database.
> One
> > thing I wonder about is let's say someone updates their shopping cart,
> you
> > can do a SQL transaction that updates your cart state and then publish a
> > message to Kafka for further processing but what if your process crashes
> in
> > between? Is there a way to do transactions that encompass both your SQL
> > database and the act of publishing a message to Kafka?
> >
> > Thanks again everyone for educating me :)
> >
> > Oli
> >
> > On Tue, May 17, 2016 at 11:26 PM, Abhaya P <ab...@gmail.com> wrote:
> >
> > > A curious question:
> > > How does database + Kafka broker solution work?
> > > Would the consumer(s) load the database and then overlay the events?
> > > Or is it that the events are overlaid on the database and the database
> is
> > > queried?
> > > I am curious on how a complete solution would look like with "database
> +
> > > Kafka" conceptually.
> > >
> > > Thanks,
> > > Abhaya
> > >
> > >
> > > On Tue, May 17, 2016 at 10:46 PM, Chris Richardson <
> > > chris@chrisrichardson.net> wrote:
> > >
> > > > Oli,
> > > >
> > > > Kafka is only a partial solution.
> > > > As I describe here (
> > > >
> > > >
> > >
> >
> http://www.slideshare.net/chris.e.richardson/hacksummit-2016-eventdriven-microservices-events-on-the-outside-on-the-inside-and-at-the-core/57
> > > > )
> > > > an event store is a hybrid of a database and a message broker.
> > > > It is a database because it provides an API for inserting events for
> an
> > > > entity and retrieving them by the entity's primary key.
> > > > It is a message broker because it provides an API for subscribing to
> > > > events.
> > > > Kafka clearly satisfies the latter but not the former.
> > > >
> > > > Just my two cents.
> > > >
> > > > Chris
> > > >
> > > > --
> > > > Microservices application platform http://eventuate.io
> > > >
> > > > On Tue, May 17, 2016 at 12:18 AM, Olivier Lalonde <
> olalonde@gmail.com>
> > > > wrote:
> > > >
> > > > > Hi all,
> > > > >
> > > > > I am considering adopting an "event sourcing" architecture for a
> > > system I
> > > > > am developing and Kafka seems like a good choice of store for
> events.
> > > > >
> > > > > For those who aren't aware, this architecture style consists in
> > storing
> > > > all
> > > > > state changes of the system as an ordered log of events and
> building
> > > > > derivative views as needed for easier querying (using a SQL
> database
> > > for
> > > > > example). Those views must be completely derived from the event log
> > > alone
> > > > > so that the log effectively becomes a "single source of truth".
> > > > >
> > > > > I was wondering if anyone else is using Kafka for that purpose and
> > more
> > > > > specifically:
> > > > >
> > > > > 1) Can Kafka store messages permanently?
> > > > >
> > > > > 2) Let's say I throw away my derived view and want to re-build it
> > from
> > > > > scratch, is it possible to consume messages from a topic from its
> > very
> > > > > first message and once it has caught up, listen for new messages
> like
> > > it
> > > > > would normally do?
> > > > >
> > > > > 2) Does it support transactions? Let's say I want to push 3
> messages
> > > > > atomically but the producer process crashes after sending only 2
> > > > messages,
> > > > > is it possible to "rollback" the first 2 messages (e.g. "all or
> > > nothing"
> > > > > semantics)?
> > > > >
> > > > > 3) Does it support request/response style semantics or can they be
> > > > > simulated? My system's primary interface with the outside world is
> an
> > > > HTTP
> > > > > API so it would be nice if I could publish an event and wait for
> all
> > > the
> > > > > internal services which need to process the event to be "done"
> > > > > processing before returning a response.
> > > > >
> > > > > PS: I'm a Node.js/Go developer so when possible please avoid Java
> > > centric
> > > > > terminology.
> > > > >
> > > > > Thanks!
> > > > >
> > > > > - Oli
> > > > >
> > > > > --
> > > > > - Oli
> > > > >
> > > > > Olivier Lalonde
> > > > > http://www.syskall.com <-- connect with me!
> > > > >
> > > >
> > >
> >
> >
> >
> > --
> > - Oli
> >
> > Olivier Lalonde
> > http://www.syskall.com <-- connect with me!
> >
>
>
>
> --
> *Christian Posta*
> twitter: @christianposta
> http://www.christianposta.com/blog
> http://fabric8.io
>

Re: Kafka for event sourcing architecture

Posted by Radoslaw Gruchalski <ra...@gruchalski.com>.
Hi Tom,

There is, indeed, the problem with replication in case of the leader change for the partition.
Hence, I think the best, best approach would to have Kafka emit events in case of:

- partition leader change
- offset file to be cleaned up

This still leaves a lot of work for the ops people to actually implement the cold storage but it makes it at least possible. From there on, it’s all about tooling.
I’ve got electricity back, I’m going to prepare a JIRA.
–  
Best regards,

Radek Gruchalski

radek@gruchalski.com
de.linkedin.com/in/radgruchalski

Confidentiality:
This communication is intended for the above-named person and may be confidential and/or legally privileged.
If it has come to you in error you must take no action based on it, nor must you copy or show it to anyone; please delete/destroy and inform the sender immediately.

On May 18, 2016 at 3:34:30 PM, Tom Crayford (tcrayford@heroku.com) wrote:

The issue I have with that log.cleanup.policy approach is how it impacts  
with replication. Different replicas often have different sets of segment  
files. There are effectively two options then:  
1. All replicas upload all their segments. This has issues with storage  
space, but is easy to implement. It's hard to reason about from a user's  
perspective though - what happens when the replicas for a partition are  
reassigned? Do we upload under some namespace by broker id? That'd mean  
reassigning replicas will change where things get stored in S3  
2. Only the leader uploads it's segments. This presents a totally different  
issue, as different brokers have different sets of segment files. To recap  
a second, segment files contain a certain set of offsets, e.g. 0-100000  
might be in one file, then 100001-200000 in another. However, there's no  
consistency of offset overlap between replicas. This means that Kafka's now  
in charge of tracking which offset it's deleted to (in some replicated  
storage), and it has to truncate files before sending them to the archive  
command. Alternatively, another option is to allow multiple overlaps in  
storage. This presents confusing behaviour for users when the leader  
changes, as there will now be overlaps in storage. Also worth thinking  
about how a cold storage proposal works with unclean leader election.  

Another point I take issue with is the fact that now we're using Kafka's on  
disk storage format as a long term API thing for the cold storage of data.  
Clients *have* to integrate against the broker code for reading on disk  
storage (which only works for JVM clients right now, furthering the already  
huge amount of work it takes to support non JVM client libraries). Right  
now that code *and* the storage format isn't public at all and is subject  
to change (aside from normal backwards compatibility concerns with on disk  
storage). With a current "a separate consumer archives to cold storage"  
approach the consumer gets to specify whatever format it likes, control  
batching in a way that makes sense for your cold storage system of choice  
(some may prefer 1GB batches, some may prefer 100MB batches etc). Doing  
this in the archiving command would be possible, but does put additional  
strain on the broker machine and complicates the archiving command  
significantly.  

Furthermore, that rough cold storage proposal, as outlined still requires  
clients to do large amounts of custom work to consume from the beginning of  
time. I think avoiding much of that custom work was much of the point of  
"why can't Kafka do infinite retention" thing. I can imagine a nicer to use  
thing in which Kafka, upon receiving an earlier offset than the beginning  
of it's queue could *also* restore the segments from cold storage one by  
one, but that seems extremely tricky to implement, if much nicer in  
practice.  

Overall, any cold storage proposal seems like a drastic change and  
complication of the role of Kafka in a system. This makes it harder to  
implement and harder to run in production. It also makes it more confusing  
to use as a customer (even if you have an ops team or a PaaS offering  
running it for you), because now you're using a long term data store, not  
an ephemeral streaming system.  

I think Kafka is a great fit in an event-sourced architecture, but not as  
the long term cold storage, just the messaging layer. For long term low  
volume event storage, a traditional database often works very well anyway  
(the control plane that powers Heroku Kafka and Heroku Postgres does  
something like this with Postgres, and it's worked extremely well for the  
8+ years the control plane has been running). For high volume, a consumer  
archiving to S3 (or other long term storage) is relatively simple to  
implement (or you can use secor which is an off the shelf dropin for most  
folk).  

On Wed, May 18, 2016 at 12:19 PM, Christian Posta <christian.posta@gmail.com  
> wrote:  

> So Kafka is a fine solution as part of an event-sourced story. It's not a  
> simple solution, but it fits.  
>  
> Kakfa can store data for a long time and you shouldn't discount this,  
> however, using it as the primary long-term data store might not be a good  
> fit if we're talking storing raw events for years and years. I think  
> someone in another thread mentioned moving these raw events to S3 or some  
> object store which is probably a good idea. Kafka can store the "head" of  
> the raw event stream as well as "snapshots" in time of the raw event stream  
> that your applications can consume. If a raw event stream ends up super  
> big, it may be impractical for an application to consume it from he  
> beginning of time to recreate its datastore anyway; thus  
> snapshots/aggregate snapshots help with this. Years and years of raw events  
> may be useful for batch analytics (spark/hadoop) as well.  
>  
> In terms of an event store, I quite like the idea of using raw events to  
> generate the projections/materialized views of domain objects AND using  
> events within those domain objects to generate new raw events. This can be  
> done nicely with Kafka feeding a DDD aggregate root --> traditional  
> database --> Kafka. You can use CDC style solutions to capture the database  
> journal log and publish events that way. Things like Kafka Connect become  
> really handy for a solution like this as well as Martin K's Bottled Water  
> project and our Debezium project: http://debezium.io ... i've got a  
> blog+video demo of all of this coming soon!  
>  
> On Wed, May 18, 2016 at 1:15 AM, Olivier Lalonde <ol...@gmail.com>  
> wrote:  
>  
> > Dave:  
> >  
> > Thanks for the suggestion, Bookkeeper looks interesting. I assume you  
> meant  
> > "more high-level interface"?  
> >  
> > Chris:  
> >  
> > Thanks Chris, I actually came across a few of your talks and articles  
> when  
> > researching this style of architecture (along with stuff by Greg Young  
> and  
> > Martin Kleppmann) and really excited to see you pop in this thread.  
> >  
> > I understand Kafka is fairly low level for what I really need. I'm not  
> > really convinced I will need random access to the event store though,  
> this  
> > seems to be a specific style of event sourcing architecture (with roots  
> > stemming from DDD?) where the application state is all kept in memory?  
> >  
> > My idea was to use a PostgreSQL to "cache" my state and do queries from  
> > (and possibly other types of databases in the future as needed). To build  
> > the PostgreSQL database or add new derived state "caches" (Greg Young  
> calls  
> > those "projections" I believe) I would just replay the event stream from  
> > event 0 with some glue code to handle the new event => database logic. It  
> > keeps things simple though I suppose it could be slow when my event  
> stream  
> > gets really big (could add snapshots as a concept eventually).  
> >  
> > I read a bit about eventuate.io but it wasn't clear to me whether this  
> was  
> > an application framework or a server (open source? commercial?).  
> >  
> > One thing that doesn't help is that we're primarily a Node.js shop and  
> all  
> > the information, tooling, examples and terminology is heavily geared  
> > towards JVM developers. I found this great talk by Stefan Kutko  
> > https://www.youtube.com/watch?v=X_VHWQa1k0k which describes a Node.js  
> > based  
> > event sourced architecture but it's a bit short on implementation  
> details.  
> >  
> > Abhaya:  
> >  
> > Also curious to hear what others have to say about this. What I'm trying  
> to  
> > achieve is to have a single unified event store from which all other data  
> > stores are derived but I'm still unsure whether Kafka is the right  
> choice.  
> > I also believe that a lot of people use Kafka primarily as a message  
> queue  
> > and keep track of CRUD style state in a more traditional ACID database.  
> One  
> > thing I wonder about is let's say someone updates their shopping cart,  
> you  
> > can do a SQL transaction that updates your cart state and then publish a  
> > message to Kafka for further processing but what if your process crashes  
> in  
> > between? Is there a way to do transactions that encompass both your SQL  
> > database and the act of publishing a message to Kafka?  
> >  
> > Thanks again everyone for educating me :)  
> >  
> > Oli  
> >  
> > On Tue, May 17, 2016 at 11:26 PM, Abhaya P <ab...@gmail.com> wrote:  
> >  
> > > A curious question:  
> > > How does database + Kafka broker solution work?  
> > > Would the consumer(s) load the database and then overlay the events?  
> > > Or is it that the events are overlaid on the database and the database  
> is  
> > > queried?  
> > > I am curious on how a complete solution would look like with "database  
> +  
> > > Kafka" conceptually.  
> > >  
> > > Thanks,  
> > > Abhaya  
> > >  
> > >  
> > > On Tue, May 17, 2016 at 10:46 PM, Chris Richardson <  
> > > chris@chrisrichardson.net> wrote:  
> > >  
> > > > Oli,  
> > > >  
> > > > Kafka is only a partial solution.  
> > > > As I describe here (  
> > > >  
> > > >  
> > >  
> >  
> http://www.slideshare.net/chris.e.richardson/hacksummit-2016-eventdriven-microservices-events-on-the-outside-on-the-inside-and-at-the-core/57  
> > > > )  
> > > > an event store is a hybrid of a database and a message broker.  
> > > > It is a database because it provides an API for inserting events for  
> an  
> > > > entity and retrieving them by the entity's primary key.  
> > > > It is a message broker because it provides an API for subscribing to  
> > > > events.  
> > > > Kafka clearly satisfies the latter but not the former.  
> > > >  
> > > > Just my two cents.  
> > > >  
> > > > Chris  
> > > >  
> > > > --  
> > > > Microservices application platform http://eventuate.io  
> > > >  
> > > > On Tue, May 17, 2016 at 12:18 AM, Olivier Lalonde <  
> olalonde@gmail.com>  
> > > > wrote:  
> > > >  
> > > > > Hi all,  
> > > > >  
> > > > > I am considering adopting an "event sourcing" architecture for a  
> > > system I  
> > > > > am developing and Kafka seems like a good choice of store for  
> events.  
> > > > >  
> > > > > For those who aren't aware, this architecture style consists in  
> > storing  
> > > > all  
> > > > > state changes of the system as an ordered log of events and  
> building  
> > > > > derivative views as needed for easier querying (using a SQL  
> database  
> > > for  
> > > > > example). Those views must be completely derived from the event log  
> > > alone  
> > > > > so that the log effectively becomes a "single source of truth".  
> > > > >  
> > > > > I was wondering if anyone else is using Kafka for that purpose and  
> > more  
> > > > > specifically:  
> > > > >  
> > > > > 1) Can Kafka store messages permanently?  
> > > > >  
> > > > > 2) Let's say I throw away my derived view and want to re-build it  
> > from  
> > > > > scratch, is it possible to consume messages from a topic from its  
> > very  
> > > > > first message and once it has caught up, listen for new messages  
> like  
> > > it  
> > > > > would normally do?  
> > > > >  
> > > > > 2) Does it support transactions? Let's say I want to push 3  
> messages  
> > > > > atomically but the producer process crashes after sending only 2  
> > > > messages,  
> > > > > is it possible to "rollback" the first 2 messages (e.g. "all or  
> > > nothing"  
> > > > > semantics)?  
> > > > >  
> > > > > 3) Does it support request/response style semantics or can they be  
> > > > > simulated? My system's primary interface with the outside world is  
> an  
> > > > HTTP  
> > > > > API so it would be nice if I could publish an event and wait for  
> all  
> > > the  
> > > > > internal services which need to process the event to be "done"  
> > > > > processing before returning a response.  
> > > > >  
> > > > > PS: I'm a Node.js/Go developer so when possible please avoid Java  
> > > centric  
> > > > > terminology.  
> > > > >  
> > > > > Thanks!  
> > > > >  
> > > > > - Oli  
> > > > >  
> > > > > --  
> > > > > - Oli  
> > > > >  
> > > > > Olivier Lalonde  
> > > > > http://www.syskall.com <-- connect with me!  
> > > > >  
> > > >  
> > >  
> >  
> >  
> >  
> > --  
> > - Oli  
> >  
> > Olivier Lalonde  
> > http://www.syskall.com <-- connect with me!  
> >  
>  
>  
>  
> --  
> *Christian Posta*  
> twitter: @christianposta  
> http://www.christianposta.com/blog  
> http://fabric8.io  
>  

Re: Kafka for event sourcing architecture

Posted by Tom Crayford <tc...@heroku.com>.
The issue I have with that log.cleanup.policy approach is how it impacts
with replication. Different replicas often have different sets of segment
files. There are effectively two options then:
1. All replicas upload all their segments. This has issues with storage
space, but is easy to implement. It's hard to reason about from a user's
perspective though - what happens when the replicas for a partition are
reassigned? Do we upload under some namespace by broker id? That'd mean
reassigning replicas will change where things get stored in S3
2. Only the leader uploads it's segments. This presents a totally different
issue, as different brokers have different sets of segment files. To recap
a second, segment files contain a certain set of offsets, e.g. 0-100000
might be in one file, then 100001-200000 in another. However, there's no
consistency of offset overlap between replicas. This means that Kafka's now
in charge of tracking which offset it's deleted to (in some replicated
storage), and it has to truncate files before sending them to the archive
command. Alternatively, another option is to allow multiple overlaps in
storage. This presents confusing behaviour for users when the leader
changes, as there will now be overlaps in storage. Also worth thinking
about how a cold storage proposal works with unclean leader election.

Another point I take issue with is the fact that now we're using Kafka's on
disk storage format as a long term API thing for the cold storage of data.
Clients *have* to integrate against the broker code for reading on disk
storage (which only works for JVM clients right now, furthering the already
huge amount of work it takes to support non JVM client libraries). Right
now that code *and* the storage format isn't public at all and is subject
to change (aside from normal backwards compatibility concerns with on disk
storage). With a current "a separate consumer archives to cold storage"
approach the consumer gets to specify whatever format it likes, control
batching in a way that makes sense for your cold storage system of choice
(some may prefer 1GB batches, some may prefer 100MB batches etc). Doing
this in the archiving command would be possible, but does put additional
strain on the broker machine and complicates the archiving command
significantly.

Furthermore, that rough cold storage proposal, as outlined still requires
clients to do large amounts of custom work to consume from the beginning of
time. I think avoiding much of that custom work was much of the point of
"why can't Kafka do infinite retention" thing. I can imagine a nicer to use
thing in which Kafka, upon receiving an earlier offset than the beginning
of it's queue could *also* restore the segments from cold storage one by
one, but that seems extremely tricky to implement, if much nicer in
practice.

Overall, any cold storage proposal seems like a drastic change and
complication of the role of Kafka in a system. This makes it harder to
implement and harder to run in production. It also makes it more confusing
to use as a customer (even if you have an ops team or a PaaS offering
running it for you), because now you're using a long term data store, not
an ephemeral streaming system.

I think Kafka is a great fit in an event-sourced architecture, but not as
the long term cold storage, just the messaging layer. For long term low
volume event storage, a traditional database often works very well anyway
(the control plane that powers Heroku Kafka and Heroku Postgres does
something like this with Postgres, and it's worked extremely well for the
8+ years the control plane has been running). For high volume, a consumer
archiving to S3 (or other long term storage) is relatively simple to
implement (or you can use secor which is an off the shelf dropin for most
folk).

On Wed, May 18, 2016 at 12:19 PM, Christian Posta <christian.posta@gmail.com
> wrote:

> So Kafka is a fine solution as part of an event-sourced story. It's not a
> simple solution, but it fits.
>
> Kakfa can store data for a long time and you shouldn't discount this,
> however, using it as the primary long-term data store might not be a good
> fit if we're talking storing raw events for years and years. I think
> someone in another thread mentioned moving these raw events to S3 or some
> object store which is probably a good idea. Kafka can store the "head" of
> the raw event stream as well as "snapshots" in time of the raw event stream
> that your applications can consume. If a raw event stream ends up super
> big, it may be impractical for an application to consume it from he
> beginning of time to recreate its datastore anyway; thus
> snapshots/aggregate snapshots help with this. Years and years of raw events
> may be useful for batch analytics (spark/hadoop) as well.
>
> In terms of an event store, I quite like the idea of using raw events to
> generate the projections/materialized views of domain objects AND using
> events within those domain objects to generate new raw events. This can be
> done nicely with Kafka feeding a DDD aggregate root --> traditional
> database --> Kafka. You can use CDC style solutions to capture the database
> journal log and publish events that way. Things like Kafka Connect become
> really handy for a solution like this as well as Martin K's Bottled Water
> project and our Debezium project: http://debezium.io  ... i've got a
> blog+video demo of all of this coming soon!
>
> On Wed, May 18, 2016 at 1:15 AM, Olivier Lalonde <ol...@gmail.com>
> wrote:
>
> > Dave:
> >
> > Thanks for the suggestion, Bookkeeper looks interesting. I assume you
> meant
> > "more high-level interface"?
> >
> > Chris:
> >
> > Thanks Chris, I actually came across a few of your talks and articles
> when
> > researching this style of architecture (along with stuff by Greg Young
> and
> > Martin Kleppmann) and really excited to see you pop in this thread.
> >
> > I understand Kafka is fairly low level for what I really need. I'm not
> > really convinced I will need random access to the event store though,
> this
> > seems to be a specific style of event sourcing architecture (with roots
> > stemming from DDD?) where the application state is all kept in memory?
> >
> > My idea was to use a PostgreSQL to "cache" my state and do queries from
> > (and possibly other types of databases in the future as needed). To build
> > the PostgreSQL database or add new derived state "caches" (Greg Young
> calls
> > those "projections" I believe) I would just replay the event stream from
> > event 0 with some glue code to handle the new event => database logic. It
> > keeps things simple though I suppose it could be slow when my event
> stream
> > gets really big (could add snapshots as a concept eventually).
> >
> > I read a bit about eventuate.io but it wasn't clear to me whether this
> was
> > an application framework or a server (open source? commercial?).
> >
> > One thing that doesn't help is that we're primarily a Node.js shop and
> all
> > the information, tooling, examples and terminology is heavily geared
> > towards JVM developers. I found this great talk by Stefan Kutko
> > https://www.youtube.com/watch?v=X_VHWQa1k0k which describes a Node.js
> > based
> > event sourced architecture but it's a bit short on implementation
> details.
> >
> > Abhaya:
> >
> > Also curious to hear what others have to say about this. What I'm trying
> to
> > achieve is to have a single unified event store from which all other data
> > stores are derived but I'm still unsure whether Kafka is the right
> choice.
> > I also believe that a lot of people use Kafka primarily as a message
> queue
> > and keep track of CRUD style state in a more traditional ACID database.
> One
> > thing I wonder about is let's say someone updates their shopping cart,
> you
> > can do a SQL transaction that updates your cart state and then publish a
> > message to Kafka for further processing but what if your process crashes
> in
> > between? Is there a way to do transactions that encompass both your SQL
> > database and the act of publishing a message to Kafka?
> >
> > Thanks again everyone for educating me :)
> >
> > Oli
> >
> > On Tue, May 17, 2016 at 11:26 PM, Abhaya P <ab...@gmail.com> wrote:
> >
> > > A curious question:
> > > How does  database + Kafka broker solution work?
> > > Would the consumer(s) load the database and then overlay the events?
> > > Or is it that the events are overlaid on the database and the database
> is
> > > queried?
> > > I am curious on how a complete solution would look like with "database
> +
> > > Kafka" conceptually.
> > >
> > > Thanks,
> > > Abhaya
> > >
> > >
> > > On Tue, May 17, 2016 at 10:46 PM, Chris Richardson <
> > > chris@chrisrichardson.net> wrote:
> > >
> > > > Oli,
> > > >
> > > > Kafka is only a partial solution.
> > > > As I describe here (
> > > >
> > > >
> > >
> >
> http://www.slideshare.net/chris.e.richardson/hacksummit-2016-eventdriven-microservices-events-on-the-outside-on-the-inside-and-at-the-core/57
> > > > )
> > > > an event store is a hybrid of a database and a message broker.
> > > > It is a database because it provides an API for inserting events for
> an
> > > > entity and retrieving them by the entity's primary key.
> > > > It is a message broker because it provides an API for subscribing to
> > > > events.
> > > > Kafka clearly satisfies the latter but not the former.
> > > >
> > > > Just my two cents.
> > > >
> > > > Chris
> > > >
> > > > --
> > > > Microservices application platform http://eventuate.io
> > > >
> > > > On Tue, May 17, 2016 at 12:18 AM, Olivier Lalonde <
> olalonde@gmail.com>
> > > > wrote:
> > > >
> > > > > Hi all,
> > > > >
> > > > > I am considering adopting an "event sourcing" architecture for a
> > > system I
> > > > > am developing and Kafka seems like a good choice of store for
> events.
> > > > >
> > > > > For those who aren't aware, this architecture style consists in
> > storing
> > > > all
> > > > > state changes of the system as an ordered log of events and
> building
> > > > > derivative views as needed for easier querying (using a SQL
> database
> > > for
> > > > > example). Those views must be completely derived from the event log
> > > alone
> > > > > so that the log effectively becomes a "single source of truth".
> > > > >
> > > > > I was wondering if anyone else is using Kafka for that purpose and
> > more
> > > > > specifically:
> > > > >
> > > > > 1) Can Kafka store messages permanently?
> > > > >
> > > > > 2) Let's say I throw away my derived view and want to re-build it
> > from
> > > > > scratch, is it possible to consume messages from a topic from its
> > very
> > > > > first message and once it has caught up, listen for new messages
> like
> > > it
> > > > > would normally do?
> > > > >
> > > > > 2) Does it support transactions? Let's say I want to push 3
> messages
> > > > > atomically but the producer process crashes after sending only 2
> > > > messages,
> > > > > is it possible to "rollback" the first 2 messages (e.g. "all or
> > > nothing"
> > > > > semantics)?
> > > > >
> > > > > 3) Does it support request/response style semantics or can they be
> > > > > simulated? My system's primary interface with the outside world is
> an
> > > > HTTP
> > > > > API so it would be nice if I could publish an event and wait for
> all
> > > the
> > > > > internal services which need to process the event to be "done"
> > > > > processing before returning a response.
> > > > >
> > > > > PS: I'm a Node.js/Go developer so when possible please avoid Java
> > > centric
> > > > > terminology.
> > > > >
> > > > > Thanks!
> > > > >
> > > > > - Oli
> > > > >
> > > > > --
> > > > > - Oli
> > > > >
> > > > > Olivier Lalonde
> > > > > http://www.syskall.com <-- connect with me!
> > > > >
> > > >
> > >
> >
> >
> >
> > --
> > - Oli
> >
> > Olivier Lalonde
> > http://www.syskall.com <-- connect with me!
> >
>
>
>
> --
> *Christian Posta*
> twitter: @christianposta
> http://www.christianposta.com/blog
> http://fabric8.io
>

Re: Kafka for event sourcing architecture

Posted by Christian Posta <ch...@gmail.com>.
So Kafka is a fine solution as part of an event-sourced story. It's not a
simple solution, but it fits.

Kakfa can store data for a long time and you shouldn't discount this,
however, using it as the primary long-term data store might not be a good
fit if we're talking storing raw events for years and years. I think
someone in another thread mentioned moving these raw events to S3 or some
object store which is probably a good idea. Kafka can store the "head" of
the raw event stream as well as "snapshots" in time of the raw event stream
that your applications can consume. If a raw event stream ends up super
big, it may be impractical for an application to consume it from he
beginning of time to recreate its datastore anyway; thus
snapshots/aggregate snapshots help with this. Years and years of raw events
may be useful for batch analytics (spark/hadoop) as well.

In terms of an event store, I quite like the idea of using raw events to
generate the projections/materialized views of domain objects AND using
events within those domain objects to generate new raw events. This can be
done nicely with Kafka feeding a DDD aggregate root --> traditional
database --> Kafka. You can use CDC style solutions to capture the database
journal log and publish events that way. Things like Kafka Connect become
really handy for a solution like this as well as Martin K's Bottled Water
project and our Debezium project: http://debezium.io  ... i've got a
blog+video demo of all of this coming soon!

On Wed, May 18, 2016 at 1:15 AM, Olivier Lalonde <ol...@gmail.com> wrote:

> Dave:
>
> Thanks for the suggestion, Bookkeeper looks interesting. I assume you meant
> "more high-level interface"?
>
> Chris:
>
> Thanks Chris, I actually came across a few of your talks and articles when
> researching this style of architecture (along with stuff by Greg Young and
> Martin Kleppmann) and really excited to see you pop in this thread.
>
> I understand Kafka is fairly low level for what I really need. I'm not
> really convinced I will need random access to the event store though, this
> seems to be a specific style of event sourcing architecture (with roots
> stemming from DDD?) where the application state is all kept in memory?
>
> My idea was to use a PostgreSQL to "cache" my state and do queries from
> (and possibly other types of databases in the future as needed). To build
> the PostgreSQL database or add new derived state "caches" (Greg Young calls
> those "projections" I believe) I would just replay the event stream from
> event 0 with some glue code to handle the new event => database logic. It
> keeps things simple though I suppose it could be slow when my event stream
> gets really big (could add snapshots as a concept eventually).
>
> I read a bit about eventuate.io but it wasn't clear to me whether this was
> an application framework or a server (open source? commercial?).
>
> One thing that doesn't help is that we're primarily a Node.js shop and all
> the information, tooling, examples and terminology is heavily geared
> towards JVM developers. I found this great talk by Stefan Kutko
> https://www.youtube.com/watch?v=X_VHWQa1k0k which describes a Node.js
> based
> event sourced architecture but it's a bit short on implementation details.
>
> Abhaya:
>
> Also curious to hear what others have to say about this. What I'm trying to
> achieve is to have a single unified event store from which all other data
> stores are derived but I'm still unsure whether Kafka is the right choice.
> I also believe that a lot of people use Kafka primarily as a message queue
> and keep track of CRUD style state in a more traditional ACID database. One
> thing I wonder about is let's say someone updates their shopping cart, you
> can do a SQL transaction that updates your cart state and then publish a
> message to Kafka for further processing but what if your process crashes in
> between? Is there a way to do transactions that encompass both your SQL
> database and the act of publishing a message to Kafka?
>
> Thanks again everyone for educating me :)
>
> Oli
>
> On Tue, May 17, 2016 at 11:26 PM, Abhaya P <ab...@gmail.com> wrote:
>
> > A curious question:
> > How does  database + Kafka broker solution work?
> > Would the consumer(s) load the database and then overlay the events?
> > Or is it that the events are overlaid on the database and the database is
> > queried?
> > I am curious on how a complete solution would look like with "database +
> > Kafka" conceptually.
> >
> > Thanks,
> > Abhaya
> >
> >
> > On Tue, May 17, 2016 at 10:46 PM, Chris Richardson <
> > chris@chrisrichardson.net> wrote:
> >
> > > Oli,
> > >
> > > Kafka is only a partial solution.
> > > As I describe here (
> > >
> > >
> >
> http://www.slideshare.net/chris.e.richardson/hacksummit-2016-eventdriven-microservices-events-on-the-outside-on-the-inside-and-at-the-core/57
> > > )
> > > an event store is a hybrid of a database and a message broker.
> > > It is a database because it provides an API for inserting events for an
> > > entity and retrieving them by the entity's primary key.
> > > It is a message broker because it provides an API for subscribing to
> > > events.
> > > Kafka clearly satisfies the latter but not the former.
> > >
> > > Just my two cents.
> > >
> > > Chris
> > >
> > > --
> > > Microservices application platform http://eventuate.io
> > >
> > > On Tue, May 17, 2016 at 12:18 AM, Olivier Lalonde <ol...@gmail.com>
> > > wrote:
> > >
> > > > Hi all,
> > > >
> > > > I am considering adopting an "event sourcing" architecture for a
> > system I
> > > > am developing and Kafka seems like a good choice of store for events.
> > > >
> > > > For those who aren't aware, this architecture style consists in
> storing
> > > all
> > > > state changes of the system as an ordered log of events and building
> > > > derivative views as needed for easier querying (using a SQL database
> > for
> > > > example). Those views must be completely derived from the event log
> > alone
> > > > so that the log effectively becomes a "single source of truth".
> > > >
> > > > I was wondering if anyone else is using Kafka for that purpose and
> more
> > > > specifically:
> > > >
> > > > 1) Can Kafka store messages permanently?
> > > >
> > > > 2) Let's say I throw away my derived view and want to re-build it
> from
> > > > scratch, is it possible to consume messages from a topic from its
> very
> > > > first message and once it has caught up, listen for new messages like
> > it
> > > > would normally do?
> > > >
> > > > 2) Does it support transactions? Let's say I want to push 3 messages
> > > > atomically but the producer process crashes after sending only 2
> > > messages,
> > > > is it possible to "rollback" the first 2 messages (e.g. "all or
> > nothing"
> > > > semantics)?
> > > >
> > > > 3) Does it support request/response style semantics or can they be
> > > > simulated? My system's primary interface with the outside world is an
> > > HTTP
> > > > API so it would be nice if I could publish an event and wait for all
> > the
> > > > internal services which need to process the event to be "done"
> > > > processing before returning a response.
> > > >
> > > > PS: I'm a Node.js/Go developer so when possible please avoid Java
> > centric
> > > > terminology.
> > > >
> > > > Thanks!
> > > >
> > > > - Oli
> > > >
> > > > --
> > > > - Oli
> > > >
> > > > Olivier Lalonde
> > > > http://www.syskall.com <-- connect with me!
> > > >
> > >
> >
>
>
>
> --
> - Oli
>
> Olivier Lalonde
> http://www.syskall.com <-- connect with me!
>



-- 
*Christian Posta*
twitter: @christianposta
http://www.christianposta.com/blog
http://fabric8.io

Re: Kafka for event sourcing architecture

Posted by Olivier Lalonde <ol...@gmail.com>.
Dave:

Thanks for the suggestion, Bookkeeper looks interesting. I assume you meant
"more high-level interface"?

Chris:

Thanks Chris, I actually came across a few of your talks and articles when
researching this style of architecture (along with stuff by Greg Young and
Martin Kleppmann) and really excited to see you pop in this thread.

I understand Kafka is fairly low level for what I really need. I'm not
really convinced I will need random access to the event store though, this
seems to be a specific style of event sourcing architecture (with roots
stemming from DDD?) where the application state is all kept in memory?

My idea was to use a PostgreSQL to "cache" my state and do queries from
(and possibly other types of databases in the future as needed). To build
the PostgreSQL database or add new derived state "caches" (Greg Young calls
those "projections" I believe) I would just replay the event stream from
event 0 with some glue code to handle the new event => database logic. It
keeps things simple though I suppose it could be slow when my event stream
gets really big (could add snapshots as a concept eventually).

I read a bit about eventuate.io but it wasn't clear to me whether this was
an application framework or a server (open source? commercial?).

One thing that doesn't help is that we're primarily a Node.js shop and all
the information, tooling, examples and terminology is heavily geared
towards JVM developers. I found this great talk by Stefan Kutko
https://www.youtube.com/watch?v=X_VHWQa1k0k which describes a Node.js based
event sourced architecture but it's a bit short on implementation details.

Abhaya:

Also curious to hear what others have to say about this. What I'm trying to
achieve is to have a single unified event store from which all other data
stores are derived but I'm still unsure whether Kafka is the right choice.
I also believe that a lot of people use Kafka primarily as a message queue
and keep track of CRUD style state in a more traditional ACID database. One
thing I wonder about is let's say someone updates their shopping cart, you
can do a SQL transaction that updates your cart state and then publish a
message to Kafka for further processing but what if your process crashes in
between? Is there a way to do transactions that encompass both your SQL
database and the act of publishing a message to Kafka?

Thanks again everyone for educating me :)

Oli

On Tue, May 17, 2016 at 11:26 PM, Abhaya P <ab...@gmail.com> wrote:

> A curious question:
> How does  database + Kafka broker solution work?
> Would the consumer(s) load the database and then overlay the events?
> Or is it that the events are overlaid on the database and the database is
> queried?
> I am curious on how a complete solution would look like with "database +
> Kafka" conceptually.
>
> Thanks,
> Abhaya
>
>
> On Tue, May 17, 2016 at 10:46 PM, Chris Richardson <
> chris@chrisrichardson.net> wrote:
>
> > Oli,
> >
> > Kafka is only a partial solution.
> > As I describe here (
> >
> >
> http://www.slideshare.net/chris.e.richardson/hacksummit-2016-eventdriven-microservices-events-on-the-outside-on-the-inside-and-at-the-core/57
> > )
> > an event store is a hybrid of a database and a message broker.
> > It is a database because it provides an API for inserting events for an
> > entity and retrieving them by the entity's primary key.
> > It is a message broker because it provides an API for subscribing to
> > events.
> > Kafka clearly satisfies the latter but not the former.
> >
> > Just my two cents.
> >
> > Chris
> >
> > --
> > Microservices application platform http://eventuate.io
> >
> > On Tue, May 17, 2016 at 12:18 AM, Olivier Lalonde <ol...@gmail.com>
> > wrote:
> >
> > > Hi all,
> > >
> > > I am considering adopting an "event sourcing" architecture for a
> system I
> > > am developing and Kafka seems like a good choice of store for events.
> > >
> > > For those who aren't aware, this architecture style consists in storing
> > all
> > > state changes of the system as an ordered log of events and building
> > > derivative views as needed for easier querying (using a SQL database
> for
> > > example). Those views must be completely derived from the event log
> alone
> > > so that the log effectively becomes a "single source of truth".
> > >
> > > I was wondering if anyone else is using Kafka for that purpose and more
> > > specifically:
> > >
> > > 1) Can Kafka store messages permanently?
> > >
> > > 2) Let's say I throw away my derived view and want to re-build it from
> > > scratch, is it possible to consume messages from a topic from its very
> > > first message and once it has caught up, listen for new messages like
> it
> > > would normally do?
> > >
> > > 2) Does it support transactions? Let's say I want to push 3 messages
> > > atomically but the producer process crashes after sending only 2
> > messages,
> > > is it possible to "rollback" the first 2 messages (e.g. "all or
> nothing"
> > > semantics)?
> > >
> > > 3) Does it support request/response style semantics or can they be
> > > simulated? My system's primary interface with the outside world is an
> > HTTP
> > > API so it would be nice if I could publish an event and wait for all
> the
> > > internal services which need to process the event to be "done"
> > > processing before returning a response.
> > >
> > > PS: I'm a Node.js/Go developer so when possible please avoid Java
> centric
> > > terminology.
> > >
> > > Thanks!
> > >
> > > - Oli
> > >
> > > --
> > > - Oli
> > >
> > > Olivier Lalonde
> > > http://www.syskall.com <-- connect with me!
> > >
> >
>



-- 
- Oli

Olivier Lalonde
http://www.syskall.com <-- connect with me!

Re: Kafka for event sourcing architecture

Posted by Abhaya P <ab...@gmail.com>.
A curious question:
How does  database + Kafka broker solution work?
Would the consumer(s) load the database and then overlay the events?
Or is it that the events are overlaid on the database and the database is
queried?
I am curious on how a complete solution would look like with "database +
Kafka" conceptually.

Thanks,
Abhaya


On Tue, May 17, 2016 at 10:46 PM, Chris Richardson <
chris@chrisrichardson.net> wrote:

> Oli,
>
> Kafka is only a partial solution.
> As I describe here (
>
> http://www.slideshare.net/chris.e.richardson/hacksummit-2016-eventdriven-microservices-events-on-the-outside-on-the-inside-and-at-the-core/57
> )
> an event store is a hybrid of a database and a message broker.
> It is a database because it provides an API for inserting events for an
> entity and retrieving them by the entity's primary key.
> It is a message broker because it provides an API for subscribing to
> events.
> Kafka clearly satisfies the latter but not the former.
>
> Just my two cents.
>
> Chris
>
> --
> Microservices application platform http://eventuate.io
>
> On Tue, May 17, 2016 at 12:18 AM, Olivier Lalonde <ol...@gmail.com>
> wrote:
>
> > Hi all,
> >
> > I am considering adopting an "event sourcing" architecture for a system I
> > am developing and Kafka seems like a good choice of store for events.
> >
> > For those who aren't aware, this architecture style consists in storing
> all
> > state changes of the system as an ordered log of events and building
> > derivative views as needed for easier querying (using a SQL database for
> > example). Those views must be completely derived from the event log alone
> > so that the log effectively becomes a "single source of truth".
> >
> > I was wondering if anyone else is using Kafka for that purpose and more
> > specifically:
> >
> > 1) Can Kafka store messages permanently?
> >
> > 2) Let's say I throw away my derived view and want to re-build it from
> > scratch, is it possible to consume messages from a topic from its very
> > first message and once it has caught up, listen for new messages like it
> > would normally do?
> >
> > 2) Does it support transactions? Let's say I want to push 3 messages
> > atomically but the producer process crashes after sending only 2
> messages,
> > is it possible to "rollback" the first 2 messages (e.g. "all or nothing"
> > semantics)?
> >
> > 3) Does it support request/response style semantics or can they be
> > simulated? My system's primary interface with the outside world is an
> HTTP
> > API so it would be nice if I could publish an event and wait for all the
> > internal services which need to process the event to be "done"
> > processing before returning a response.
> >
> > PS: I'm a Node.js/Go developer so when possible please avoid Java centric
> > terminology.
> >
> > Thanks!
> >
> > - Oli
> >
> > --
> > - Oli
> >
> > Olivier Lalonde
> > http://www.syskall.com <-- connect with me!
> >
>

Re: Kafka for event sourcing architecture

Posted by Chris Richardson <ch...@chrisrichardson.net>.
Oli,

Kafka is only a partial solution.
As I describe here (
http://www.slideshare.net/chris.e.richardson/hacksummit-2016-eventdriven-microservices-events-on-the-outside-on-the-inside-and-at-the-core/57)
an event store is a hybrid of a database and a message broker.
It is a database because it provides an API for inserting events for an
entity and retrieving them by the entity's primary key.
It is a message broker because it provides an API for subscribing to events.
Kafka clearly satisfies the latter but not the former.

Just my two cents.

Chris

-- 
Microservices application platform http://eventuate.io

On Tue, May 17, 2016 at 12:18 AM, Olivier Lalonde <ol...@gmail.com>
wrote:

> Hi all,
>
> I am considering adopting an "event sourcing" architecture for a system I
> am developing and Kafka seems like a good choice of store for events.
>
> For those who aren't aware, this architecture style consists in storing all
> state changes of the system as an ordered log of events and building
> derivative views as needed for easier querying (using a SQL database for
> example). Those views must be completely derived from the event log alone
> so that the log effectively becomes a "single source of truth".
>
> I was wondering if anyone else is using Kafka for that purpose and more
> specifically:
>
> 1) Can Kafka store messages permanently?
>
> 2) Let's say I throw away my derived view and want to re-build it from
> scratch, is it possible to consume messages from a topic from its very
> first message and once it has caught up, listen for new messages like it
> would normally do?
>
> 2) Does it support transactions? Let's say I want to push 3 messages
> atomically but the producer process crashes after sending only 2 messages,
> is it possible to "rollback" the first 2 messages (e.g. "all or nothing"
> semantics)?
>
> 3) Does it support request/response style semantics or can they be
> simulated? My system's primary interface with the outside world is an HTTP
> API so it would be nice if I could publish an event and wait for all the
> internal services which need to process the event to be "done"
> processing before returning a response.
>
> PS: I'm a Node.js/Go developer so when possible please avoid Java centric
> terminology.
>
> Thanks!
>
> - Oli
>
> --
> - Oli
>
> Olivier Lalonde
> http://www.syskall.com <-- connect with me!
>