David A Good

DynamoDB Repository Layer Isolation in Java

January 19, 2021

This is based on this repo: https://github.com/helloworldless/dynamodb-java-sdk-v2.

Here are the details of how we maintain isolation:

  1. The Repository interface is public and is implemented by the package-private DynamoDbRepository
  2. The Repository is defined in terms of public, database-agnostic value classes (in other words, nothing related to DynamoDB here)
  3. The DynamoDbRepository uses MapStruct to effortlessly convert the database-agnostic value classes into DynamoDB entities (@DynamoDbBean)
  4. The DynamoDB entities (@DynamoDbBean) also live inside the repository package. They are public but should ideally be package-private. However, making them non-public would require switching to manually wiring the DynamoDB schema as opposed to using the SDK’s more convenient, annotation-driven schema capability.

Software engineer crafting full-stack, cloud-native solutions for enterprise. GitHub | LinkedIn | Twitter