1

I can insert an Object(annotated with @DynamoDBTable) in DynamoDB using to following code

@Autowired
private SdnInformationRepository sdnInformationRepository;

SdnInformation inf = new SdnInformation();
inf.setFirstName("firstname");
inf.setLastName("lastname");
sdnInformationRepository.save(inf);

Here is my repository

public interface SdnInformationRepository extends 
CrudRepository<SdnInformation, String> { 
}

and my model

@DynamoDBTable(tableName = "SdnList")
public class SdnInformation {

@DynamoDBHashKey(attributeName = "Id")
@DynamoDBAutoGeneratedKey
private String id;

private String firstName;

private String lastName;

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

}

Everything works fine here. I want to know whether it is possible to insert a List/Set of SdnInformation objects at once? If I insert a huge number of such objects individually it takes too much time. So I want something like

Set<SdnInformation> listToInsert = new HashSet<SdnInformation>();
... some code to fill my set with thousands of objects ...
sdnInformationRepository.save(listToInsert);
2
  • 1
    The CrudRepository interface has a saveAll method... Commented Sep 11, 2018 at 14:55
  • Wow! I missed that. saveAll method does the job! Commented Sep 11, 2018 at 16:45

1 Answer 1

1

DynamoDB does not support inserting multiple items at the same time. Batching multiple requests (up to 25) is possible but they are still considered separate requests by Dynamo (ie it is possible for some to succeed and some to fail).

Of course, at a high level, a mapper can pretend that it is inserting a list of items but underlying there will still be separate operations.

Update (based on comment)

If it’s speed you’re after, you can parallelize the inserts. As long as you have write capacity available you can get a lot of speed improvement that way. But it can get expensive fast. And there is a limit of 1000 inserts/second per partition.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah I can verify that using saveAll function I can save multiple records together but the overall time is almost the same as inserting individual records.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.