• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to implement Idempotency with POST method ?  RSS feed

 
Karn Kumar
Ranch Hand
Posts: 153
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,


One way is to do with database check for the duplicate record insertion....

But this is bot the ideal way ...

If you have any idea kindly suggest.


Thanks.....!!!

Regards,
Chetan
 
Lanny Gilbert
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm assuming you're using a Java Servlet to handle the POST??

Checking the DB using whatever key is passed in the POST *is* the correct way, because servlets are multi-threaded, unless you use the "not recommended" single threaded model.

Usually, the way that is handled is if the record is already in the DB, you do an UPDATE. If not, you do an INSERT.

Or, it might be in your case that if the record is already in the DB, then you reply with a "record exists" back to the 2nd (and subsequent) client who try to insert the same record.

Or, if you're using something like EhCache in your AppServer, you could have a hashmap of the data and check that..

But, you're going to need to do a lookup of some kind to validate that the incoming data is not already in your system.
 
Karn Kumar
Ranch Hand
Posts: 153
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lanny,


You got my problem correctly and i am doing check with the database . But i mean is there is another way so that i can reduce my Database call.

Can you explain about EhCache ?

Thanks for the reply....

Regards,
Chetan
 
Lanny Gilbert
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This link will give you all the info you need, including code samples for caching results that should remove your need for DB calls.

http://ehcache.org/

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!