Robin Bajaj
Robin Bajaj

Reputation: 2072

how to share a common data structure in high performance java web service applications

I am developing a couple of web services - one to BUY a product and another to VALIDATE a product. Multiple clients will be calling the BUY (around 250/sec) and same for VALIDATE. They need to query and update a tabular data structure before calling the backend.

I have a feeling that using a relational database table like Oracle to maintain this common data structure will slow down things because of network latency (assuming database and queries are tuned optimally). I have been proposed EhCache and Hazelcast but I prefer using a database table because I know it better.

Can anyone confirm if hitting a database across a network could prove to be a bottleneck for an application that's supposed to serve 250-300 transactions per second?

Certainly we are okay if the server instance goes down and we lose the in-memory representation of the data structure.

Upvotes: 1

Views: 525

Answers (2)

Yair Zaslavsky
Yair Zaslavsky

Reputation: 4137

That really depends what your application is doing.
Of course you can use a database machine with expensive hardware, and expensive network hardware.
The question is - is this really needed?
As stated in some of the comments - Caching will mostly help you in case that you perform mostly READ (more READ requests than write requests). In order to optimize you should consider indexing (for example - if you store addressed, you can consider indexing by an "ip" field, assuming that most queries that are not by ID are by this field) ,
which is just one part of correct DB schema planning (other aspects of this may be to avoid complex joins between tables, by modelling your data properly as much as possible), and maybe even a NoSQL database.
What about scaling You should use a distributed cache/distibuted data structure if you go for caching and scaling.
For example, infinispan can help here.
You can also improve performance by using in memory/in process (i.e - its code is in a jar and is co-hosted on the JVM of the application) such as h2 - this can further reduce querying time. But once again, it really depends on your specific use cases, what you described is unfortunately too general.

Upvotes: 1

Francisco Spaeth
Francisco Spaeth

Reputation: 23903

IMO, caching will help just if the update requests is lower than the query request... imagine you cache as a big map that will store values already queried if you update every time rows on server you need to update the too, and you update the cache by invalidating its entry in order to perform request to the DB again.

Upvotes: 0

Related Questions