question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redis indexation

See original GitHub issue

In #94, I was talking about some ways to improve redis implementation performance, mostly when there are a large number of events (or snapshots). The problem with actual the implementation is the scan which usually need to scan every events (or snapshots) of an aggregate, and then make the necessary calculations to only take needed events.

I have made a quick test with my production data. I have an aggregate with +46K events with a total amount of +117K I tried to scan all the keys (only scanning, no get or mget) using 2 strategies:

  • I made a common scan on all the keys. It took 6181ms.
  • I put all the aggregate keys in a sorted set (members score was the event version), and made a zrange on all the keys. It took 415ms

I think that sorted sets could be a good option to index aggregates keys, at least for 2 reasons:

  • It seems more efficient to scan all the keys at once, for an aggregate
  • It will be more efficient to get keys between 2 revisions, for an aggregate (like you need to do when you reload state from a snapshot and an event)

This means that the database need to be indexed at first, and the index maintained. So whenever a client connects, we need to check if the store has been indexed, and if it’s not the case, scan all the aggregates, and scan for their events and snapshots keys, and finally index the keys (events and snapshots separated obviously). Once done, each time an event is added, its key should be added to the corresponding sorted set.

What do you think about this solution? I’ll try to work on an implementation. But if you have any remarks, objections or suggestions, don’t hesitate!

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
rehiacommented, Sep 5, 2018

@TyGuy hi!

Sorry, but I couldn’t take some time to start something on this. You can do it, if you have time for it.

The solution I suggested could be a good one, but as usual, it must first be validated on the field.

I hop you’ll find more time than me 😅 Good luck !

0reactions
TyGuycommented, Sep 5, 2018

@rehia do you still have interest in this, or plans to execute on it?

We are sitting with around 30k events in redis, and noticing it slowing down as well. I think this solution (indexing on aggregateId and using sorted sets) would be awesome!

If you don’t have plans to continue it or work on it, would you be willing to share a WIP branch with your implementation? If/when I find some time, I could pick up where you left off, and carry this forward.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Secondary indexing | Redis
The simplest secondary index you can create with Redis is by using the sorted set data type, which is a data structure representing...
Read more >
Indexing Patterns | Redis
Indexing in Redis is quite different from other databases, as your particular usage and data will determine the best strategy for indexing.
Read more >
Does Redis uses indexes to get the data? - Stack Overflow
Redis GET command has a O(1) complexity, meaning that it will always get the data in the same amount of time (not counting...
Read more >
Indexed (Spring Data Redis 3.0.0 API)
Annotation Interface Indexed ... Mark properties value to be included in a secondary index. Uses Redis SET for storage. The value will be...
Read more >
StackExchange.Redis - GitHub
General purpose redis client. Contribute to StackExchange/StackExchange.Redis development by creating an account on GitHub. ... Redis/docs/index.md.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found