Report a fraud if voter tries to vote twiceMaintain state between redis caches on EC2 instancesHow to develop/assemble a SOAP cache in JAVAWebApi - Redis cache vs Output cacheArchiteture of voting based website/appRedis: using two instances or just one (caching and storage)?RedisTemplate keys(String pattern) method is giving empty setWay to improve Rest Webservice performance which call other APIRedis compare and set atomicHow to avoid repeating query in concurrencyStackExchange.Redis.RedisConnectionException: System.OutOfMemoryException:

Example of a relative pronoun

How do I create uniquely male characters?

Set-theoretical foundations of Mathematics with only bounded quantifiers

What typically incentivizes a professor to change jobs to a lower ranking university?

Motorized valve interfering with button?

Modification to Chariots for Heavy Cavalry Analogue for 4-armed race

How can bays and straits be determined in a procedurally generated map?

What are these boxed doors outside store fronts in New York?

How long does it take to type this?

Is there really no realistic way for a skeleton monster to move around without magic?

If Manufacturer spice model and Datasheet give different values which should I use?

Work Breakdown with Tikz

Japan - Plan around max visa duration

Compute hash value according to multiplication method

How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?

Infinite past with a beginning?

How to report a triplet of septets in NMR tabulation?

Why can't I see bouncing of a switch on an oscilloscope?

Can a German sentence have two subjects?

Prevent a directory in /tmp from being deleted

A Journey Through Space and Time

I probably found a bug with the sudo apt install function

Why Is Death Allowed In the Matrix?

What Brexit solution does the DUP want?



Report a fraud if voter tries to vote twice


Maintain state between redis caches on EC2 instancesHow to develop/assemble a SOAP cache in JAVAWebApi - Redis cache vs Output cacheArchiteture of voting based website/appRedis: using two instances or just one (caching and storage)?RedisTemplate keys(String pattern) method is giving empty setWay to improve Rest Webservice performance which call other APIRedis compare and set atomicHow to avoid repeating query in concurrencyStackExchange.Redis.RedisConnectionException: System.OutOfMemoryException:






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a list of candidateId, voterId as incoming request to the "backendService".



This backend service checks if the voterID has not already been voted to any of the candidateId, if so it will increment the candidateId count in the cache as below :



| CandidateId | count |



| ABC | 5 |



| XYZ | 10 |



| MNO | 100 |



The problem with above approach is if we scale up the "backendService" to 3 - 4 instances and the same voterID tries to vote to many candidates as below incoming request and all of the below comes at a SAME TIME:



 candidateId : 1, voterId : "ABC"
candidateId : 2, voterId : "ABC"
candidateId : 3, voterId : "ABC"


Each of the "backendService" will pick one of the above request to process.



In this case all 3 instances check that VoterID has not already voted to any candidate in the cache at a same time ( where are the voter's ID who has already give there vote is being stored) and then all the 3 service instance will wrongly updates the count at a same time for all the 3 candidateId which is casted by the same voterID in the cache which is wrong.



I am looking for a solution on how to avoid such cases.



Currently all the details are stored in distributed cache (REDIS).










share|improve this question
























  • How do you keep votes in memory ? Can you use a map in a synchronized block where its key is voterId and the value is vote as a cache, and return exception if the specified key exists while putting in it ?

    – Emre Acar
    Mar 8 at 6:03







  • 1





    Use database locking. If such a conflict is less likely to occur, you can improve performance by using optimistic locking.

    – Kartik
    Mar 8 at 6:04











  • All the details are stored in REDIS cache and serializing the updates would slow down.

    – Yathish Manjunath
    Mar 8 at 6:14

















0















I have a list of candidateId, voterId as incoming request to the "backendService".



This backend service checks if the voterID has not already been voted to any of the candidateId, if so it will increment the candidateId count in the cache as below :



| CandidateId | count |



| ABC | 5 |



| XYZ | 10 |



| MNO | 100 |



The problem with above approach is if we scale up the "backendService" to 3 - 4 instances and the same voterID tries to vote to many candidates as below incoming request and all of the below comes at a SAME TIME:



 candidateId : 1, voterId : "ABC"
candidateId : 2, voterId : "ABC"
candidateId : 3, voterId : "ABC"


Each of the "backendService" will pick one of the above request to process.



In this case all 3 instances check that VoterID has not already voted to any candidate in the cache at a same time ( where are the voter's ID who has already give there vote is being stored) and then all the 3 service instance will wrongly updates the count at a same time for all the 3 candidateId which is casted by the same voterID in the cache which is wrong.



I am looking for a solution on how to avoid such cases.



Currently all the details are stored in distributed cache (REDIS).










share|improve this question
























  • How do you keep votes in memory ? Can you use a map in a synchronized block where its key is voterId and the value is vote as a cache, and return exception if the specified key exists while putting in it ?

    – Emre Acar
    Mar 8 at 6:03







  • 1





    Use database locking. If such a conflict is less likely to occur, you can improve performance by using optimistic locking.

    – Kartik
    Mar 8 at 6:04











  • All the details are stored in REDIS cache and serializing the updates would slow down.

    – Yathish Manjunath
    Mar 8 at 6:14













0












0








0


2






I have a list of candidateId, voterId as incoming request to the "backendService".



This backend service checks if the voterID has not already been voted to any of the candidateId, if so it will increment the candidateId count in the cache as below :



| CandidateId | count |



| ABC | 5 |



| XYZ | 10 |



| MNO | 100 |



The problem with above approach is if we scale up the "backendService" to 3 - 4 instances and the same voterID tries to vote to many candidates as below incoming request and all of the below comes at a SAME TIME:



 candidateId : 1, voterId : "ABC"
candidateId : 2, voterId : "ABC"
candidateId : 3, voterId : "ABC"


Each of the "backendService" will pick one of the above request to process.



In this case all 3 instances check that VoterID has not already voted to any candidate in the cache at a same time ( where are the voter's ID who has already give there vote is being stored) and then all the 3 service instance will wrongly updates the count at a same time for all the 3 candidateId which is casted by the same voterID in the cache which is wrong.



I am looking for a solution on how to avoid such cases.



Currently all the details are stored in distributed cache (REDIS).










share|improve this question
















I have a list of candidateId, voterId as incoming request to the "backendService".



This backend service checks if the voterID has not already been voted to any of the candidateId, if so it will increment the candidateId count in the cache as below :



| CandidateId | count |



| ABC | 5 |



| XYZ | 10 |



| MNO | 100 |



The problem with above approach is if we scale up the "backendService" to 3 - 4 instances and the same voterID tries to vote to many candidates as below incoming request and all of the below comes at a SAME TIME:



 candidateId : 1, voterId : "ABC"
candidateId : 2, voterId : "ABC"
candidateId : 3, voterId : "ABC"


Each of the "backendService" will pick one of the above request to process.



In this case all 3 instances check that VoterID has not already voted to any candidate in the cache at a same time ( where are the voter's ID who has already give there vote is being stored) and then all the 3 service instance will wrongly updates the count at a same time for all the 3 candidateId which is casted by the same voterID in the cache which is wrong.



I am looking for a solution on how to avoid such cases.



Currently all the details are stored in distributed cache (REDIS).







java caching concurrency system-design






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 9:25







Yathish Manjunath

















asked Mar 8 at 5:57









Yathish ManjunathYathish Manjunath

1,2861515




1,2861515












  • How do you keep votes in memory ? Can you use a map in a synchronized block where its key is voterId and the value is vote as a cache, and return exception if the specified key exists while putting in it ?

    – Emre Acar
    Mar 8 at 6:03







  • 1





    Use database locking. If such a conflict is less likely to occur, you can improve performance by using optimistic locking.

    – Kartik
    Mar 8 at 6:04











  • All the details are stored in REDIS cache and serializing the updates would slow down.

    – Yathish Manjunath
    Mar 8 at 6:14

















  • How do you keep votes in memory ? Can you use a map in a synchronized block where its key is voterId and the value is vote as a cache, and return exception if the specified key exists while putting in it ?

    – Emre Acar
    Mar 8 at 6:03







  • 1





    Use database locking. If such a conflict is less likely to occur, you can improve performance by using optimistic locking.

    – Kartik
    Mar 8 at 6:04











  • All the details are stored in REDIS cache and serializing the updates would slow down.

    – Yathish Manjunath
    Mar 8 at 6:14
















How do you keep votes in memory ? Can you use a map in a synchronized block where its key is voterId and the value is vote as a cache, and return exception if the specified key exists while putting in it ?

– Emre Acar
Mar 8 at 6:03






How do you keep votes in memory ? Can you use a map in a synchronized block where its key is voterId and the value is vote as a cache, and return exception if the specified key exists while putting in it ?

– Emre Acar
Mar 8 at 6:03





1




1





Use database locking. If such a conflict is less likely to occur, you can improve performance by using optimistic locking.

– Kartik
Mar 8 at 6:04





Use database locking. If such a conflict is less likely to occur, you can improve performance by using optimistic locking.

– Kartik
Mar 8 at 6:04













All the details are stored in REDIS cache and serializing the updates would slow down.

– Yathish Manjunath
Mar 8 at 6:14





All the details are stored in REDIS cache and serializing the updates would slow down.

– Yathish Manjunath
Mar 8 at 6:14












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55057507%2freport-a-fraud-if-voter-tries-to-vote-twice%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55057507%2freport-a-fraud-if-voter-tries-to-vote-twice%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

Алба-Юлія

Захаров Федір Захарович