Build a backend for Comment Threads like Reddit

by CodeRecipe devs

June 25, 2019

This example implementation shows how to build a backend for nested comments like Reddit or Slack. To add and retrieve users’ comments, frontend requests are sent to the system through AWS API Gateway and comments are stored in DynamoDB.

Quick Notes
Build a backend for Comment Threads like Reddit

Solution Details

Comments are managed using a dependency graph on AWS Lambda that is connected to DynamoDB for persistence. Using a graph structure (built using networkx library) allows for an infinitely nested comments thread. In the DynamoDB table, parent and child comments are tracked using parentId and threadId where a comment with parentId as -1 is the root comment. The example is headless and can be plugged into any custom frontend. By using serverless architecture, it allows for easy maintenance and deployment and flexible usage based pricing.


Prerequisites Setup AWS Credentials
Make sure you have AWS access key and secrete keys setup locally, following this video here

Install Serverless Cli

npm install serverless

Download the code locally

serverless create --template-url --path nested-comments-serverless

Deploy to the cloud

cd nested-comments-serverless

npm install

serverless deploy --stage <your-stage-name>
source code