Problem I'm trying to solve
===========================

I have a worker process which changes an attribute of a resource(lets say MyResource) by accumulating values from some JSON messages the worker receives. I'm trying to come up with a best way to avoid duplicate accumulation even if the same JSON message is received twice or more times by the worker process.

Here's what I've tried
======================

Solution 1
----------

Every JSON message has a unique timestamp which depends on when the JSON message was created, I saved that timestamp on MyResource and rejected a JSON message if it has timestamp value lower than the one on MyResource. 

### Problem

Since the whole architecture is asynchronous, the messages might be received in any order and not necessarily in same order as they were created.

Solution 2
----------

I created a new attribute (say added\_ids) on MyResource. Every JSON message has an unique id, I appended that id to MyResource.added\_ids. And every time accumulating used added\_ids for already processed JSON messages.

### Problem

I'm using mongo to store MyResource. Every MyResource document started to blow up with this array of ids, since the JSON messages for each MyResource are a lot. Also lookup in array is an expensive operation.

I'm looking for
===============

I'm looking for an answer which can handle the asynchronous nature and also does not blow up my mongo documents. Also I'm not looking for an exact solution, is there a algorithm/pattern which is used to solve similar kind of problems? I tried googling, but I don't know what to call this problem to get relevant results.