Hey everyone, welcome back to the channel! Today, we're tackling a common issue faced by developers: deleting inactive user data from our system. We'll be working within the TypeScript repository of the productivity app, Increaser. Although the source code for this project is in a private repository, you can find all the reusable code in the RadzionKit repository.
Increaser is a paid web application that offers a free trial period. Many users try the app and never return, leaving their data stored in our database and S3 storage, which incurs costs. To address this, we'll create a Lambda function that runs daily to clean up inactive user data.
First, we’ll cover the environment variables. The getEnvVar function ensures all necessary environment variables are present. If a non-paying user hasn't opened the app in the last 60 days, we'll send them a warning email. If they still haven't opened the app in the last 90 days, we'll delete their account. The lastVisitAt field within the user resolver helps us track the last visit.
We’ll fetch all users from the database, using DynamoDB and the scan operation to retrieve users. The totalScan function handles pagination. Once we have all users, we iterate over each user, skipping those with an active subscription or lifetime deal. If a user hasn't visited the app after receiving an account deletion email, we'll delete their account.
Deleting a user involves removing their data from the users table, S3 bucket, and updating related tables. Even though we don’t have email marketing campaigns, we save the user's email for potential future contact. We use AWS SES for sending emails and rate-limit the function to avoid sending more than 14 emails per second.
Our Lambda function is hosted on AWS using Terraform. We define the S3 backend for Terraform's state, create an S3 bucket for the Lambda function code, and set up the aws_lambda_function resource. An IAM role and policy grant necessary permissions, and a CloudWatch Events rule triggers the Lambda function daily.
I hope this video gives you a clear understanding of how to handle inactive user data in your applications. Check out the description for links to the RadzionKit repository and the corresponding YouTube videos for more detailed guides. Thanks for watching, and see you in the next one!
Demo: https://increaser.org
Source code: https://github.com/radzionc/radzionkit
Mentioned in this video:
Simplifying TypeScript Backend Development: A Comprehensive Guide: • Simplifying TypeScript Backend Develo...
Accelerate your work and reach your goals faster with https://increaser.org – where deep work, time mastery, and habit shaping converge for your success! 💪🚀
Смотрите видео How to Clean Up Inactive User Data in TypeScript: Step-by-Step Guide онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Radzion Dev 25 Август 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 56 раз и оно понравилось 6 людям.