Live data from Hacker News

EventStore: Open-Source, Functional Database with Complex Event Processing in JS

github.com

41–50 of 64 posts

Re: EventStore: Open-Source, Functional Database with Complex Event Processing in JS

#41
post #7

Earlier quoted context omitted.

It isn’t that contradictory. You can have data in a functional language. One of the common features of a functional language that separates it from imperative is data immutability. In this case it’s a database of immutable data. I personally understand exactly what they’re talking about when they call it a functional database.

I don't understand how this is useful. The purpose of functional programming isn't to make everything immutable, but to use immutability to prevent unnecessary change of state which can result in flaky code. So where's the usefulness in a functional Database? Also this still isn't functional. Is adding records to a set not mutation?

git is a functional database, well almost. Datomic is what you get when you finish that idea. it does mostly all the same sorts of things postgres does, but like git, the strength is it has idealized caching at all layers and scales horizontally / serverless. it is also just better (do you know anyone who thinks git sucks and wants to go back to SVN or CVS?)

Re: EventStore: Open-Source, Functional Database with Complex Event Processing in JS

#42

Earlier quoted context omitted.

Hi, I'm a Redux maintainer. Got any examples of this? Also, how do you feel it's better than a typical Redux app setup?

It seems like the main difference with a reducer is that the reducer just returns `state`, not `(state, action)`. I'm reading this for the first time but that's how I'm reading it. But y'all must be storing this `(point-in-time-state, action-that-produced-state)` somewhere, because the Redux Chrome plugin displays this data. Was I wrong in thinking the Chrome plugin was just visualizing data already stored by Redux?

No, the core Redux store does _not_ store any action history by itself. It's simply:

    function createStore(reducer) {
        var state
        var listeners = []
        
        function getState() { return state  }
        
        function dispatch(action) {
            state = reducer(state, action)
            listeners.forEach(listener => listener())
        }
    }
It's the Redux DevTools that do the real work of actually saving an action log, like what was described above. In fact, canceling actions does actually work by re-running the actions in the same sequence, minus the ones that are being skipped, to generate the new state.

That logic has been split out into its own package, which you can see in the https://github.com/zalmoxisus/redux-devtools-instrument repo.

Very vaguely related side note: earlier this year, I spent a couple days to add an "action stack trace" tab to the Redux DevTools Extension. When you click on an action, in addition to seeing the action contents, state tree, and diff, you can now also see an actual formatted stack trace that shows you exactly where the action was dispatched from (including the actual code if you've got sourcemaps enabled). Sadly, the extension maintainer has been MIA recently, so we're considering forking it into the Redux org. Until then, you can download my custom build of the extension here: https://github.com/zalmoxisus/redux-devtools-extension/issue...

Re: EventStore: Open-Source, Functional Database with Complex Event Processing in JS

#43

Earlier quoted context omitted.

It seems like the main difference with a reducer is that the reducer just returns `state`, not `(state, action)`. I'm reading this for the first time but that's how I'm reading it. But y'all must be storing this `(point-in-time-state, action-that-produced-state)` somewhere, because the Redux Chrome plugin displays this data. Was I wrong in thinking the Chrome plugin was just visualizing data already stored by Redux?

No, the core Redux store does _not_ store any action history by itself. It's simply: function createStore(reducer) { var state var listeners = [] function getState() { return state } function dispatch(action) { state = reducer(state, action) listeners.forEach(listener => listener()) } } It's the Redux DevTools that do the real work of actually saving an action log, like what was described above. In fact, canceling ac…

That's really interesting. I honestly haven't given Redux DevTools much thought despite the fact I use it daily as a core part of my workflow. I thought, like I said before, it was mostly just visualizing artifacts produced normally by Redux. Makes the browser extension much more interesting!

edit: Here's the link where it's implemented in redux-devtools if anyone else is curious https://github.com/reduxjs/redux-devtools/blob/master/src/cr...

Re: EventStore: Open-Source, Functional Database with Complex Event Processing in JS

#44
post #16

I've played around recently with a Redux inspired frontend architecture where the complex, nested reducers are replaced with a single one that simply adds every action to an immutable linked list (i.e, `(state, action) => ({state, action})`. This means all the business logic that would normally live in reducers can be moved over to memoized selectors, which fixes the awkward difference in how reducers and selectors a…

I wrote a similar comment before, viewing redux as a realization of the event sourcing pattern: https://news.ycombinator.com/item?id=17061827 You can go even further and use the exact same "events" or "actions" for event sourcing on the server side too. You just need to save the list of actions to the server. This lets you do realtime sync and multiplayer really easily!

This.

It makes Implementing CQRS in a single service really easy. GETs load the event log, replay and display the results while POSTs send a command that gets translated into an event. If it is valid it gets appended to the log. This approach is storage agnostic: It doesn’t matter how the log ultimately gets stored

Re: EventStore: Open-Source, Functional Database with Complex Event Processing in JS

#45
post #16

I've played around recently with a Redux inspired frontend architecture where the complex, nested reducers are replaced with a single one that simply adds every action to an immutable linked list (i.e, `(state, action) => ({state, action})`. This means all the business logic that would normally live in reducers can be moved over to memoized selectors, which fixes the awkward difference in how reducers and selectors a…

If actions are fully deterministic, a list of actions is isomorphic to a list of events: you can always determine what happened by looking at what was requested.

A list of all past states avoids the determinism problem, but the consequence of each action is only implicit in the difference between two states.

For event sourcing, "the state" is the list of events, and what you're calling "the state" is just another selector/projection.

Re: EventStore: Open-Source, Functional Database with Complex Event Processing in JS

#46

Earlier quoted context omitted.

I've used a MySQL table `event_store` with fields `uuid`, `playhead`, `payload` and `recorded_on`; works fine.

How did you manage horizontal scaling with this approach?

If you need total system order then that will always be your bottleneck, although you can make it very fast by scoping it to just a sequence number generator and doing the actual work in separate processes.

Otherwise, most event sourcing uses different "streams" of events for different application functions, so you can shard by stream in whatever way works for you.

Re: EventStore: Open-Source, Functional Database with Complex Event Processing in JS

#47
post #16

I've played around recently with a Redux inspired frontend architecture where the complex, nested reducers are replaced with a single one that simply adds every action to an immutable linked list (i.e, `(state, action) => ({state, action})`. This means all the business logic that would normally live in reducers can be moved over to memoized selectors, which fixes the awkward difference in how reducers and selectors a…

A lot of people are starting to use RxJS [1] instead of Redux for this exact reason.

https://medium.com/@jamestthompson3/beyond-counters-using-re...

https://medium.freecodecamp.org/how-to-build-a-github-search...

https://twitter.com/gabrielvergnaud/status/10573757954155233...

[1] https://github.com/reactivex/rxjs

Re: EventStore: Open-Source, Functional Database with Complex Event Processing in JS

#48
post #7

Earlier quoted context omitted.

It isn’t that contradictory. You can have data in a functional language. One of the common features of a functional language that separates it from imperative is data immutability. In this case it’s a database of immutable data. I personally understand exactly what they’re talking about when they call it a functional database.

I don't understand how this is useful. The purpose of functional programming isn't to make everything immutable, but to use immutability to prevent unnecessary change of state which can result in flaky code. So where's the usefulness in a functional Database? Also this still isn't functional. Is adding records to a set not mutation?

I don't know anything about EventStore, but immutability and databases go surprisingly nicely together. Mash together versioned data and persistent data structures, and you get to store history efficiently (and can have separate operations for excising history). See eg Datomic.

Re: EventStore: Open-Source, Functional Database with Complex Event Processing in JS

#49
post #17

I've had to break it to my client that had built a CRUD application using CQRS and Event Sourcing that they have wasted a huge amount of resources on a misguided architecture. A rewrite is pending.

I would gladly hear more about this scenario. Why did the initial approach not work? How is the follow-up going to improve on that? And why was a rewrite the best way to fix things? Thanks for any insight you can share.

Re: EventStore: Open-Source, Functional Database with Complex Event Processing in JS

#50
post #9

We use this heavily in production and to good effect. It has its downsides (doesn't every product) but we have found it works well once you've grasped them. If you have a primarily .NET focused team, have plenty of event-driven applications and want to do CQRS / Event Sourcing for some of your applications I would recommend it as a starter step towards that. It gives you a lot 'out of the box' which is great when sta…

We just wrote our own on top of Sql Server. Runs fine for thousands of accounts with many events per day. We currently host it on the smallest azure sql scale level. We have virtually unlimited scaling with azure, and should have no problem sharding it in future because we include extra metadata (event type, accountid, etc.) so we could choose to shard on any of those dimensions.
Post reply on HN