Using an In-Memory Key Value Store to scale Java Apps

Businesses today are developing high traffic web applications that serve tens of thousands or even millions of concurrent users. A Majority of these applications are developed in Java and are deployed in a load-balanced web farm consisting of Linux or Windows servers. They incorporate an In-Memory Key value store to do so.

In such a high traffic environment, two things are very important. First is that your application performance should maintain response rates even under peak loads (scalability) and secondly, your application should stay up all the time and should not crash (high availability).

Incidentally, Java web application architectures can easily accommodate both needs. A load-balanced web farm allows you to add more web/app servers seamlessly. Having more than one web/app server means you don’t have a single point of failure, hence high availability.

Despite all of this, the data storage and databases just cannot cope with this much load. That is why, you see your application slowing down under peak loads because the database becomes the bottleneck. It is so because it cannot distribute its data and processing to multiple servers like your application tier can. So, although you can scale up your database server by purchasing a more expensive hardware but you cannot scale out by adding more and more database servers. Scaling up is very limited.

Java In-Memory Key Value Store

So, what is the solution to all of this? Fortunately, you can use an In-Memory Key Value Store to keep frequently used data in the cluster and reduce those expensive database trips. An In-Memory Key Value Store can be distributed to multiple servers which means you can linearly scale to handle greater transaction loads. This is what sets an In-Memory Key Value Store apart from your database server.

An In-Memory Key Value Store like TayzGrid works by simply storing all data as a combination of “keys” and “values”. In case of multiple servers, the key determines on which server the data is stored. It can do that by using a hash value algorithm just like in a HashMap data structure. The interface for you is a simple HashMap. Don’t be confused by the word Key value store and key value database they are one and the same thing.

The way to benefit from an In-Memory Key Value Store is to keep your frequently used data in it. This reduces your expensive database trips because 80% of the time you find your data in this Key Value Store. As a result, your database is no longer a bottleneck for you.

Example of an In-Memory Key Value Store


try {
    Cache = TayzGrid.initializeCache("myDistributedCache");
    customer = (Customer) cache.get(customerId);
    //If key not found in cache, Load from the database
    if (customer == null) {
        //Your logic goes here
        ResultSet rs = stmt.executeQuery(" ... ");
        if (rs.next()) {
            customer = new Customer();
            customer.setId(rs.getString("CustId"));

            //Cache key for future use
            cache.insert(customerId, customer,
                  null, null, null, CacheItemPriority.Default);
        }
    }
} catch (Exception exp) {
    throw exp;
}

TayzGrid, a fast and scalable Open Source In-Memory Data Grid for Java released under Apache 2.0 license, is one easy & feature rich solution. It is used as an In-Memory Key Value Store by Java applications. Because it is 100% JCache (JSR 107) compliant you can plug it in without any code changes to your JCache based application.

TayzGrid is developed from NCache source code into a native Java product. NCache is a powerful .NET Distributed Cache which has been the market leader for the last 10 years. This makes TayzGrid also a mature product.

Since TayzGrid is Open Source, it is totally free to use. If your application is business sensitive, you can choose to use the Professional or Enterprise Editions that come with full support and more features.

Learn more about TayzGrid from the link below or download a fully working copy:

Download TayzGrid         Edition Comparison

About Basit Anwer
Basit is a Solution Architect at Alachisoft - provider of a leading In-Memory Data Grid for Java called TayzGrid and for .NET called NCache. Alachisoft has been a market leader for 10 years in the .NET market with NCache.
This entry was posted in NoSQL and tagged , , . Bookmark the permalink.

2 Responses to Using an In-Memory Key Value Store to scale Java Apps

  1. Pingback: Spring Cache with In-Memory Data Grid -

  2. Pingback: Scale Java Spring Applications with Distributed Cache - NCache Blog

Leave a Reply

Your email address will not be published. Required fields are marked *