How I implemented the adjacency list design pattern using DynamoDB
About me
I am a Senior Software Engineer at Swiggy.
Why I wanted to implement adjacency list design pattern using DynamoDB
I was evaluating over implementing my graph usecase in Amazon Neptune or Neo4j but chose to go with DDB instead at the end.
How I approached implementing adjacency list design pattern using DynamoDB
I basically segregated each item as either an edge or a node. Also, as per my access patterns, I created a secondary index in addition to a primary index.
Challenges I faced
- Should i create a GSI or go for duplicating the edges to support the access patterns?
- Primary key design - How can I make it composite to support my usecase?
- Graph traversal - Querying on primary index vs secondary index
Key takeaways
- GSI was eventually chosen as in the other approach, we might need transactional support for every edge insertion.
- The partition and sort keys were made composite by making it a combination of entity type and entity id which eases the process of filtering by entity types.
- The graph was built in a bi-color format and the entities were divided into primary and secondary.
Tips and advice
- No SQL Workbech was used thoroughly in the process and it is a great resource for everyone who is working on DDB.
- The AWS documentation is a gold mine.
Final thoughts and next steps
I am currently done with the implementation and am planning to scale it by adding more primary and secondary entities to serve the usecase.