Posts

All Practice Series

Image
Introduction This is a comprehensive page about the technologies I have shared in series format. You can view brief introductions and links to directly access each series you are interested in. In the field of software development, to deploy a product from the initial idea to its release, the standard process typically involves several stages as follows: Database : Designing and implementing the database according to business requirements, storing data during the system's operation. Backend : Handling the main logic of the system, communicating with the database and services. Frontend : Building the interface for users to interact with the system, which could be a desktop, mobile, or web application. This usually includes implementing UI/UX and integrating APIs from the backend. DevOps : Deploying the system for use, which can be done on a server or in the cloud. Testing : Applying testing methods to ensure the product meets the standards for release. Of course, these are just stan...

Seeding bulk records with Snaplet Seed and PostgreSQL

Image
Introduction In the previous article, I provided a basic guide on how to use @snaplet/seed to seed data quickly. In this article, I will show you how to generate a large amount of data in a short time, approximately 1,000,000 records, which is useful when you need to perform performance testing. You can apply a similar approach to larger datasets like several million records, using a streaming mechanism to avoid Out of Memory (OOM) errors caused by allocating too much memory at once and overloading the system. I will explain two different approaches here: Coding: chunking data and writing each small part to the database Database: creating a CSV file and using a command to copy that data directly into PostgreSQL Prerequisites You need to set up Prisma, PostgreSQL and @snaplet/seed before continuing, you can check out the previous articles for instructions. Detail First, let us create the file prisma/seed/seed.ts import {faker} from '@faker-js/faker' import {createSeedClient}...

API Security with NextJS Rewrites and Proxy

Image
Introduction NextJS Proxy and Rewrites are a powerful duo that helps manage and route requests flexibly. NextJS Rewrites act as an internal proxy, essentially mapping one URL path to another. Its biggest advantage is hiding the actual URL of the underlying core server, while transforming requests from Cross-Origin to Same-Origin on the client interface. NextJS Proxy  allows you to execute code before a request is completed. As a result, you can easily intervene to implement features like Authentication, authorization, or centralized Rate Limiting, reducing the load on the core API server and maximizing performance. Previously, this function was called middleware, the name change to Proxy aims to confirm that this is an ultra-lightweight Gateway layer: It should only be used for tasks such as Routing, Rewrite, Redirect and managing Header/Cookie. NextJS encourages moving Granular Authorization logic or complex session management into Server Components or Server Actions to take...

Using Server Actions in NextJS

Image
Introduction NextJS Server Actions is a powerful feature that allows you to perform data mutations directly on the server without having to create API Routes manually. Distinguishing between Routes Handle and Server Actions Similarities: Both are code defined on the Server Both can be used in Server components and Client components Differences: Use Routes Handle if you need to call APIs from outside such as from partners or mobile Use Server Actions for internal CRUD processing operations The outstanding advantages of Server Actions compared to Routes Handle include: Tight integration with Form: Works smoothly with the action attribute of HTML forms. Progressive Enhancement: The application can still function basically even when JavaScript has not finished loading or is disabled. Security: Automatically protects against CSRF attacks and keeps sensitive processing logic on the server side. Code simplification: Reduces boilerplate code when connecting between Client and Server. When...