Posts

Showing posts with the label patterns

Design Patterns

Image
Introduction Gang of Four (GoF) is a term referring to a group of 4 authors ( Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides ) who published the classic book Design Patterns: Elements of Reusable Object-Oriented Software in 1994 . The book summarizes 23 design patterns commonly used to solve recurring object-oriented programming ( OOP ) design problems. The main benefit of GoF Design Patterns is providing standardized solutions to common problems, making source code easier to maintain, extend and creating a common language for developers when discussing software architecture. These 23 design patterns are divided into 3 main groups: Creational Patterns Factory Method : Defines an interface for creating an object, but lets subclasses decide which class to instantiate. Abstract Factory : Provides an interface for creating families of related or dependent objects without specifying their concrete classes. Builder : Separates the construction of a complex obj...

CACHE-ASIDE, WRITE-AROUND, WRITE-THROUGH

Image
Introduction In this article, we will explore how to implement the simplest and most commonly used patterns, including CACHE-ASIDE (LAZY LOADING), WRITE-AROUND and WRITE-THROUGH . Among these, CACHE-ASIDE and WRITE-AROUND are often used together. I will use NestJS combined with Redis and Postgres , so please set up the necessary components before starting. You can review the theoretical content in my previous article . Detail First, create the schema as follows in drizzle-orm/schema/schema.ts : import { bigserial, decimal, integer, pgTable, serial, text, timestamp, varchar, } from 'drizzle-orm/pg-core' export const products = pgTable ( 'products' , { id : bigserial ( 'id' , { mode : 'number' }). primaryKey (), name : varchar ( 'name' , { length : 255 }). notNull (), description : text ( 'description' ), price : decimal ( 'price' , { precision : 10 , scale : 2 }). notNull (), createdAt : timesta...