Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,026 | Comments: 44,842

filter by tags archive

Streamlined RavenDB, Part I

time to read 2 min | 312 words

One of the things that we worked very hard on (and are still working very hard) is making RavenDB as streamlined as possible, in the sense of making it very easy to do things that you commonly have to do.

Case in point, the Future Posts feature of this blog. Yesterday I went a bit overboard and posted about 10 posts in the space of two hours. (No, this isn’t my usual rate). That led to something that I didn’t quite foreseen:


We did have a limit on the number of future posts that we will show, but that limit was set to 15, and as you can see, it is actually pretty hard to look at things when we have so many, so instead I decided that we should have the following:


Just a minor UI change, but we now need to also change the data that we gather, or do we? Let us look at the code:


The only change that I actually had to do was modify the Take() from 15 to 5, and also ask the query to give me the query statistics. Because such as operation (pages + full count) is so common, RavenDB make it super cheap to do so. You don’ t need to issue a separate query, and you don’t need to do anything nor are you incurring any additional costs.

The information is already there.



Nice. I do like the way of getting things done with Raven. Write a dot and check what features are provided. By the way, are all this extensions (like cache and stats) written in a feature-mode you often describe? Is it a vertical, from the client to the raven server implementation?

Ayende Rahien

Scooletz, Some of them are, bundles, for example. Some are more complex, caching for example, requires us to take explicit action in several places, as did profiling. It really depend on what you are doing, and what extensions points we have there to cover them.


So I guess usual paging also may be implemented by one query? Nice, never liked the absense of this feature in other database servers.

Ayende Rahien

Idsa, Yep, that is a single call away, and requires no extra work

Daniel Lidström

Where is the 8 coming from? Are you calculating it in the view?

Ayende Rahien

Daniel, It is TotalResults - Posts.Count

Daniel Lidström

Ok thanks, that clarified things a bit for me.

Bogdan Marian

@Ayende Hats on, master! I really, really like the total count + page in the same query... By the way, what are you using behind the call MapTo? AutoMapper or something else?

Bogdan Marian

@Ayende Are you not concerned by the price of using AutoMapper? As far as I know, it's using Reflection for mapping ...

Ayende Rahien

Bogdan, In a word, no. http://ayende.com/blog/4811/performance-numbers-in-the-pub

James Morcom

My main concern with automapper is that renaming a property on my entity could break my views without me realising it - as the corresponding property on the viewmodel won't be renamed.

Marcel Medak

Hi Ayende, I see that you explicitly query for posts which are not flagged as deleted. I suppose that most of the time only posts are queried which aren't flagged as deleted and that this must be done explicitly. So my question is if this is something you can avoid?

Ayende Rahien

Marcel, Actually, yes, we could have created an index that would do this filtering for us, certainly.

Gian Maria Ricci

Man, this is really really really coool!!!!!


Ayende for a long time I would love ask you ...why is Mark Zuckerberg the creator of FB but and not you???

p.s. sometimes (when I have no money) I think mmm ...why i'm not the creator of FB :( ...then I think mmm ...but ayende is not even :)

Tang Biao

Sorry to ask a junior question, is the source code that contains this sample on github, and which repository? I feel like to take a look.


During 1 minute the post is not shown as public post and not as future post. See also: http://ayende.com/blog/26625/you-canrsquo-t-cache-datetime-now

Ayende Rahien

Bas, That is okay, it is perfectly fine or this to happen, since the cost of avoiding it may be too high.


What is the cost of changing < into <= in WhereIsPublicPost() or changing > into >= in FuturePosts()

Ayende Rahien

Bas, That isn't the issue, the issue is that they are using slightly different clocks to do that. It may be that they hit just in the 1 minute mark, and get two different minutes

Ayende Rahien



Jeff Handley

By having the .Statistics call before the .Where(x => x.IsDeleted == false), does that make the statistics include deleted posts in the counts?

Ayende Rahien

Jeff, No, it doesn't matter where you put the Statistics call

Tang Biao

Thanks, ayende. Just started to follow your blogs. It has so many things to learn.

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats