{"id":21937415,"url":"https://github.com/tanishkamarrott/serverlesschatapp-websocket-api-lambda-dynamodb-integration","last_synced_at":"2025-03-22T14:22:36.174Z","repository":{"id":211933869,"uuid":"730276103","full_name":"TanishkaMarrott/ServerlessChatApp-WebSocket-API-Lambda-DynamoDB-Integration","owner":"TanishkaMarrott","description":"DynamoWave Chat is a serverless chat appliction utilising AWS Lambda, DynamoDB, and WebSocket API for real-time communication. This architecture focuses on System Design Principles, ensuring high availability, scalability, security, cost-efficiency, and optimal performance.","archived":false,"fork":false,"pushed_at":"2024-09-19T08:04:20.000Z","size":329,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T13:48:21.264Z","etag":null,"topics":["aws","aws-cloudformation","chat-application","cloud-computing","cost-optimization","dynamo-db","lambda-functions","real-time-communication","scalability","serverless","websocket"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TanishkaMarrott.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-11T15:19:10.000Z","updated_at":"2024-09-19T08:04:23.000Z","dependencies_parsed_at":"2023-12-26T20:31:21.572Z","dependency_job_id":"7a2901d6-fadf-44a1-bb26-272863f7e7c0","html_url":"https://github.com/TanishkaMarrott/ServerlessChatApp-WebSocket-API-Lambda-DynamoDB-Integration","commit_stats":{"total_commits":33,"total_committers":1,"mean_commits":33.0,"dds":0.0,"last_synced_commit":"f04a3097a5643240f54f262853d45abaeb3df231"},"previous_names":["tanishkamarrott/serverlesschatapp-websocket-api-lambda-dynamodb-integration"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TanishkaMarrott%2FServerlessChatApp-WebSocket-API-Lambda-DynamoDB-Integration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TanishkaMarrott%2FServerlessChatApp-WebSocket-API-Lambda-DynamoDB-Integration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TanishkaMarrott%2FServerlessChatApp-WebSocket-API-Lambda-DynamoDB-Integration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TanishkaMarrott%2FServerlessChatApp-WebSocket-API-Lambda-DynamoDB-Integration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TanishkaMarrott","download_url":"https://codeload.github.com/TanishkaMarrott/ServerlessChatApp-WebSocket-API-Lambda-DynamoDB-Integration/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244967603,"owners_count":20539985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-cloudformation","chat-application","cloud-computing","cost-optimization","dynamo-db","lambda-functions","real-time-communication","scalability","serverless","websocket"],"created_at":"2024-11-29T01:19:43.240Z","updated_at":"2025-03-22T14:22:36.155Z","avatar_url":"https://github.com/TanishkaMarrott.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# DynamoWave Chat - A Serverless, Real-time Chat Application\n\n**DynamoWave Chat** is a modern, scalable, serverless real-time chat application built using **AWS Lambda**, **DynamoDB**, and **API Gateway**.\n\n➡️ **Core Focus**: Enhancing scalability, performance, and security from a non-functional standpoint.\n\n---\n\n## System Architecture \u0026 Components\n\n\u003cimg width=\"500\" alt=\"System Architecture\" src=\"https://github.com/TanishkaMarrott/ServerlessChatApp-WebSocket-API-Lambda-DynamoDB-Integration/assets/78227704/afed5865-ebe0-4292-b402-b74216650655\"\u003e\n\n---\n\n## Workflow Overview\n\n1. **Establish WebSocket connection**: Two-way communication between the client and server.\n2. **ConnectHandler Lambda**: Triggered when a connection is established, inserting the `connectionId` into **ConnectionsTable**.\n3. **Notification to Client**: Once the connection is established, the client is notified.\n4. **SendMessageHandler Lambda**: Iterates through `connectionIds` and sends messages to connected clients.\n5. **DisconnectHandler Lambda**: Cleans up by removing inactive `connectionIds` after the session ends.\n\n---\n\n## Services \u0026 Purpose\n\n| **Service**           | **Identifier**       | **Purpose**                                                            |\n|-----------------------|----------------------|------------------------------------------------------------------------|\n| **API Gateway**        | WebSocket API        | Enables real-time communication.                                        |\n| **DynamoDB**           | ConnectionsTable     | Tracks and manages active connections.                                  |\n| **AWS Lambda**         | ConnectHandler       | Records new connections for operational monitoring.                     |\n|                       | DisconnectHandler    | Removes inactive connections from the registry.                         |\n|                       | SendMessageHandler   | Handles reliable communication among connected clients.                 |\n|                       | DefaultHandler       | Notifies clients when the connection has been established.              |\n\n---\n\n## Design Considerations\n\n### Availability \u0026 Reliability Improvements\n\n1. **Reserved Concurrency for Critical Lambdas**: Critical Lambda functions have reserved concurrency quotas to ensure compute availability during peak times and prevent throttling.\n   \n   ➡️ Allocating resources ensures the application remains functional even during high load periods.\n\n2. **Data Durability via Point-In-Time Recovery (PITR)**: Enabled PITR for **DynamoDB** to restore data to any second in the past 35 days, ensuring data availability and fault tolerance, even in case of accidental overwrites or deletions.\n\n   ➡️ Simplifies data recovery without operational overhead or over-provisioning costs.\n\n3. **Backpressure Resilience**: Implemented API Gateway **throttling** and **rate limiting** to ensure backend services aren't overwhelmed during peak usage.\n\n   ➡️ Defines a maximum threshold of incoming requests and caps client requests to avoid service downtime or DDoS attacks.\n\n4. **Resilience to Zonal Failures**: While the application is resilient to zonal outages, to improve availability in production systems, **DynamoDB Global Tables** and regional redundancy with Route 53 DNS failover could be implemented.\n\n   ➡️ Provides higher availability for mission-critical applications and geographically distributed user bases.\n\n---\n\n## Code Optimizations for Lambda Reliability\n\n1. **Error Handling**: Incorporated error handling mechanisms in Lambda functions to prevent cascading failures and ensure system stability.\n   \n2. **Retry Mechanisms**: Implemented **exponential backoff** for critical functions to recover from transient errors such as network failures or database operations.\n\n   ➡️ Increases the likelihood of successful message delivery without overwhelming the system.\n\n3. **Graceful Error Recovery**: Configured a Dead Letter Queue (DLQ) to capture and reprocess failed messages, ensuring **zero data loss**.\n\n---\n\n## Performance Optimizations\n\n1. **Dynamic Auto-scaling for DynamoDB**: Dynamically adjusts capacity based on fluctuating workloads to ensure cost-effective scalability.\n\n   ➡️ Automatically scales based on demand, reducing costs during idle times and increasing capacity during peak times.\n\n2. **Custom Lambda Warmer**: Implemented a Lambda warmer function to reduce cold starts and improve performance for sporadically used functions.\n\n   ➡️ Configured a **CloudWatch event** to trigger the warmer function, maintaining low-latency performance.\n\n---\n\n## Security Features\n\n1. **API Gateway Resource Policies**: Enforced HTTPS-only requests to ensure secure transport for all connections.\n   \n2. **KMS Encryption for DynamoDB**: Secures all data at rest with **KMS encryption**, protecting sensitive user information.\n\n3. **Least Privilege IAM Roles**: Pruned down **IAM policies** for Lambda service roles to enforce least-privilege access, minimizing risks of privilege escalation.\n\n4. **Throttling for DDoS Mitigation**: API throttling prevents potential DDoS attacks by limiting the number of requests a user or bot can send in a given time.\n\n---\n\n## Future Enhancements\n\n1. **WAF Integration**: Adding a Web Application Firewall (WAF) on top of API Gateway to protect against excessive resource consumption and ensure application availability.\n\n   ➡️ Managed and custom rules will prevent potential security threats.\n\n2. **CloudWatch Alarms \u0026 SNS Integration**: Configuring **real-time alerts** for abnormal API usage patterns or security incidents via CloudWatch alarms and SNS notifications.\n\n   ➡️ Improves monitoring and operational insights.\n\n---\n\n## Contributions\n\nWe welcome suggestions to further improve the architecture or performance of **DynamoWave Chat**. Feel free to contact me at **tanishka.marrott@gmail.com**.\n\n---\n\n## Credit Attribution\n\nSpecial thanks to [AWS](https://aws.amazon.com/) for providing the foundational architecture guidelines for this project: [AWS WebSocket API Chat App Guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/websocket-api-chat-app.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanishkamarrott%2Fserverlesschatapp-websocket-api-lambda-dynamodb-integration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanishkamarrott%2Fserverlesschatapp-websocket-api-lambda-dynamodb-integration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanishkamarrott%2Fserverlesschatapp-websocket-api-lambda-dynamodb-integration/lists"}