Codementor Events

How I implemented the adjacency list design pattern using DynamoDB

Published Nov 18, 2020Last updated Nov 25, 2020
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

  1. Should i create a GSI or go for duplicating the edges to support the access patterns?
  2. Primary key design - How can I make it composite to support my usecase?
  3. Graph traversal - Querying on primary index vs secondary index

Key takeaways

  1. GSI was eventually chosen as in the other approach, we might need transactional support for every edge insertion.
  2. 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.
  3. The graph was built in a bi-color format and the entities were divided into primary and secondary.

Tips and advice

  1. No SQL Workbech was used thoroughly in the process and it is a great resource for everyone who is working on DDB.
  2. 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.

Discover and read more posts from Krishna Rathi
get started
post commentsBe the first to share your opinion
Show more replies