Posts

Showing posts with the label query

Guide to Querying and Pagination with AWS DynamoDB in NestJS

Image
Introduction In my previous article, I provided a basic guide on initializing and using AWS DynamoDB, but in this article, we will delve deeper into QueryCommand. In AWS DynamoDB, the Query method allows you to search for data based on the primary key (Partition Key) and filter conditions (Sort Key). To optimize performance and cost, DynamoDB supports a Pagination mechanism through the ExclusiveStartKey and LastEvaluatedKey parameters. Applying pagination not only reduces the data transfer load but also enables the application to handle large data tables smoothly, ensuring system stability. Detail Use AWS CDK to create the file lib/dynamodb-gsi-stack.ts import * as cdk from "aws-cdk-lib" import * as dynamodb from "aws-cdk-lib/aws-dynamodb" import { Construct } from "constructs" export class DynamoDbGsiStack extends cdk . Stack { constructor ( scope : Construct , id : string , props ?: cdk . StackProps ) { super (scope, id, props) ...

Implement Caching Strategies with React Query

Image
Introduction You can view the theoretical content about Caching strategies presented here These Caching Patterns are not only used on the Backend but can also be implemented on the Frontend You only need to replace the role of Redis typically used with Memory (or use Local Storage, IndexedDB on the Browser ), while replacing the query fetching data from the Database with response data from the Server API In this article, I will guide you on using React Query combined with IndexedDB (using @tanstack/react-query-persist-client and idb-keyval ) to implement Caching strategies in a simple and effective way Cache patterns CACHE-ASIDE (Lazy Loading) & READ-THROUGH This is the default mechanism of useQuery . Cache-Aside : Check the cache first, if it does not exist, fetch from the API and save to the cache. Read-Through : The client interacts through an abstraction layer (hook) and the hook automatically decides whether to retrieve data from the cache or the server. REFRESH-AHEA...