Category Archives: Uncategorized

The what and why of GraphQL


GraphQL is a query language for APIs that allows us to write queries that define the data that we receive. But why do we need one more layer? The answer to this question lies in understanding the problem that we face once our API starts evolving. As our API evolves we add/remove new parameters and it gets consumed by different clients.


We can understand GraphQL by an analogy, first, let’s try to understand what is the purpose of SQL, SQL is a structured query language to access data from the database. If we compare REST endpoint to be a data source(aka table) then the endpoint is like a source of all the information in the resource. But there is no similar technology to query the API.

Let’s try to understand this by an example, assume that there is an API that exposes customer information.

Each customer has an order and each order has multiple line items. If we want to display order details for a customer, we need to make a call to get all orders, and then for each order, we need to make a call to get order details and for each order detail, we need to make a call to fetch line item. This is a lot of calls just to display order details.

GraphQL can provide a solution where we can query this information in a single call and its responsibility of the GraphQL server to make other calls and combine these. This will save lots of network calls.

On top of this GraphQL solves the following problems:-

Cluttered API: Every API starts clean but as it evolves, new parameters are added which is required for all clients. So effectively the client needs to fetch the details even if it’s not going to be used. This creates problem considering the wastage of network bandwidth.

Dumb endpoint: Traditional API does not have the capability to provide aggregate functionality. The endpoint has a very limited capability to store or retrieve information in different criteria.

Under fetching: It means not getting enough information in a single call and forces the client to make further calls to get full information.

Over fetching: It defines a situation where an API client fetches too much information that is not required.

Aggregator: This maps to the backend for the front end pattern. If we have multiple endpoints it becomes the responsibility of the client to aggregate these API for a single-use case.

No Contract: And last but not least is there is no intelligent contract between backend and front end to talk.

In next section, I will explain how GraphQL solves these problems with examples.

Source Code:

Hibernate configuration to analyse query

Last day I was working on an application to increase its performance. I found 3 configurations that helped me to analyse query and get rid of unwanted queries.

hibernate.show_sql: true | false

hibernate.format_sql: true | false

Above two parameter can be configured to to display the hibernate queries. To my utter surprise even a simple application makes so many queries.

hibernate.generate_statistics : true|false this displays the hibernate statistics

Session Metrics {
0 nanoseconds spent acquiring 0 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
0 nanoseconds spent preparing 0 JDBC statements;
0 nanoseconds spent executing 0 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)

This gives the details about all the activity in executing a query.

Both of these information can be used to tweak query and configuration to optimize hibernate performance.

Redis – really a swiss army knife

I am exploring redis and its many capabilities and really blown away by the different ways we can use it to solve scalability problem. other than using it as a fast read/write data store it can be used and message oriented middle ware(aka pub/sub mode) and a streaming platform(like Kafka).

Here are couple of article about its pub/sub and streaming capabiliites.

Its really a swiss army knive!

DBeaver Analysing Query

Last week we were working a project where we need to analyze some query and found an interesting way to check it. We were DBeaver DB client. It has a nice feature where you can check the query parameter.

Below screencast displays how to find the expensive query.

Spring Quartz – Running many JOB at same instance

Last week I was working on a project where I need to schedule same Jobs for multiple clients at different time interval. I crated a Job class and scheduled it at different cron expression. But to my surprise when I triggered two job at same time only one of them get executed and to make it worse it was random. Sometime, job 1 gets executed sometime job2 get executed. Then after a lot of debugging i found that quartz fire an event and how many jobs can be executed for that even is determined by a parameter org.quartz.scheduler.batchTriggerAcquisitionMaxCount This tell that how many jobs can be scheduled when its triggered at same instance.


I get never enough of vert.x, everything I watch this video it feels new.



Behavior Trait of an Engineer

I read an article almost 10 years back that describes the behavior of an engineer. At that time I was very impressed because it really explained my behavior. Last Friday when we were discussing why an engineer behaves like that I realized that most of the point that we discussed is answered in that article. After much effort and searching, I found that at

chocolatey rocks!

Its quite a long time since i opened my Windows machine and started setting up development environment. I was about to install all software then I realised that there is a fantastic package manager for Windows called chocolatey. It makes life much simpler. Simply run command like Linux and install the packages.


Reactive System

The concept of a reactive system has always fascinated me. How to design a system which can be resilient at the core with varying load and remain fault tolerant. I started exploring it with this course. When I started this course this seems like a black magic but as I keep exploring more and more this started making sense. Especially after going through below presentation.


Bitcoin economy and furure?

I was reading Chapter 8 “Bitcoin Economics and Currency Creation” of this book and realized that Bitcoin is like Gold, petroleum or any other natural resources. Its availability is limited. We can create only 21 million bitcoins and it is decreasing after every 4 years. When it first launched in 2009 there were 50 new bitcoins that became available every 10 minutes, and then it dropped to 25 bitcoin after four years; four years later it dropped to 12 ½ which is where it’s at now. So every 10 minutes on average, about 12 and a half bitcoin come into existence. That amount is going to reduce every four years in half until the year 2140 when the very last bitcoin will be awarded.

This is different from any other currency where central bank and print and supply the money to monetary system anytime. The limited supply of bitcoins makes it different than traditionally used currency. This difference makes me think that how it will impact the economy in long-term, considering if we are going to use bitcoin for the medium of exchange.

Here is my thought, on this. If people know that they have limited supply if bitcoins, they will start hoarding it, no one will spend money and this will push the value of bitcoin higher. As the value of bitcoin increases, the price of an item decreases(i.e you can buy the same quantity in 90 rupees, what you were buying in 100 rupees). As no one wants to spend their bitcoin because people know that value is going to increase and they can buy more stuff in future than they can do it now. This will push the economy into deflation loop. The main question is, is it good or bad?  My thought is that its neither good or bad? If you keep any intervention(say government or banks) this will stabilize by itself. Lower and lower price of the item encourages people to find a way to decrease the price and it encourages them to innovate. and moreover, once the price of the item is decreased enough, then people will again start spending them and it will eventually find an equilibrium.

The same is true for the inflationary economy, but here government or central bank had control and they can tweak the economy.

What I understand is that neither of the Inflationary or Deflationary economies is good or bad. Its the government intervention which makes things different and bitcoin will provide a way to bypass these interventions.