title: How to prevent duplicate keys with S3?
body: <p>How can it be possible to implement in an application logic a way to prevent duplicate keys given the eventual consistency nature of S3. </p>
  
  <p>So one way to check if a key exists is: </p>
  
  <pre><code>public boolean exists(String path, String name) {
      try {
          s3.getObjectMetadata(bucket, getS3Path(path) + name); 
      } catch(AmazonServiceException e) {
          return false;
      }
      return true;
  }
  </code></pre>
  
  <p>Is there a guarantee that when we gate our application logic with this, it will always return whether the key exists or not given, again the eventual consistency of S3? Let's say two requests came with both the exact same key/path would one get the response that it exists (e.g. by <code>exists() == true</code>) or both will be stored but just in different versions? </p>
  
  <p><em>I would like to point out that I am using S3 as document storage (similar to a JSON storage)</em></p>