After ad-hoc analysis, many of you put your most valuable queries to repeated work in internal dashboards or front and center in your product. As your data volume and query complexity grow, you might find yourself asking “can I get access to these insights even faster? Can I improve my product’s experience by loading my customer’s metrics at the blink of an eye?” The answer is yes.
Data sent to Keen is available for querying almost immediately. We strongly believe that quick access empowers you to make decisions and build features that accurately reflect the state of your businesses world.
Query Caching allows you to trade this instant accuracy (or ‘freshness’) in exchange for increased query speed. The primary use case of caching is for queries that don’t need to have up-to-the-second answers, but that need to be answered as quickly as possible. If you’ve got a monthly, weekly, or even daily dashboard you are probably less concerned with the data from the last five minutes. But you certainly don’t want to wait over a minute to look at your historical trends!
Does your day ever feel like this?
Check out your product dashboard. Look at those charts. Up and to the right. Look at your Stephen Curry bobblehead. Up and down. Aw yeah, everything looks great. Boss emails a question. Back to your dashboard. Time to refresh. Loading. Loading. Loading. Are you still waiting for the {“result”: “valuable information”} to load, or are you already getting up to get your fourth cup of coffee and maybe play some foosball with Mike?
How many minutes are wasted due to slow loading dashboards? How many of your users leave your site before their visualizations finish loading? If you get frustrated waiting 111 seconds for a big query to finish, you can’t expect them to stick around. And I can’t speak for your code, but it’s not going to be happy blocking and waiting for an answer to “most popular cat shirts” to determine what recommendations to show.
Alright, better alt-tab back to your dashboard. You notice your acquisition funnel looks a little low in the last 30 seconds! Look to your right. Look to your left. Do you have an emergency lever you can pull to enhance your product immediately? Of course not. As a human, you probably never manually make drastic changes based on the last 30 seconds of behavior. You try to steer your product based on longer-term trends.
What you want, what your customers value, what your product needs is not always up-to-the-second accuracy but reliably rapid results. What your slow dashboard or product needs to leverage is Query Caching.
How to add Query Caching
Adding max_age to a Javascript query is as simple as adding a max_age parameter to your Keen queries:
var count = new Keen.Query("count", { eventCollection: "pageviews", groupBy: "property", timeframe: "this_7_days", maxAge: 300 });
So go ahead, add the Caching max_age parameter into any query you wish was snappier! If you have any questions about query caching, building dashboards, or data analysis, don’t hesitate to reach out to us or ping us on Slack!