Posts

Facade Design Pattern

Image
Introduction The Facade is a structural design pattern . It helps create a simple intermediary object that interacts with multiple systems (such as subsystems ). The responsibilities of the Facade Pattern include: Simplifying complex interactions with systems through the intermediary Facade object. Hiding the complex internal operations of subsystems, making them easier to use. Frequency of use: quite high. Problem and solution In cases where some processes require interaction with multiple services or third-party systems, and these processes are needed repeatedly in various places within the system, the typical solution might be to copy and paste the logic to those places. However, this leads to duplicated code in many locations, making maintenance and updates difficult when there are changes. The solution is to use the Facade Pattern to create an intermediary object to communicate with subsystems. This allows for the implementation of complex logic in a centralized and well-defin...

Implementing Microservices with NodeJS TypeScript using the Moleculer Framework

Image
Introduction Moleculer is a fast, modern, and powerful microservices framework for NodeJS . It helps build efficient, reliable, and highly scalable services. Originally designed for JavaScript , Moleculer now supports Typescript and offers a CLI tool that creates boilerplates as easily as Nest , Next , Vite React , and Angular. Implementing in an Existing NodeJS Project If you already have a NodeJS project and want to integrate Moleculer , it's simple. Just install the package and use the provided APIs . yarn add moleculer To create a service like this: import { ServiceBroker } from 'moleculer' const broker = new ServiceBroker () broker . createService ({ name: 'math' , actions: { add ( ctx ) { return Number ( ctx . params . a ) + Number ( ctx . params . b ) }, }, }) broker . start () . then (() => broker . call ( 'math.add' , { a: 1 , b: 2 })) . then (( res : number ) => console . log ( '1 + 2 =' ...

Using fluent-ffmpeg to work with videos in NodeJS

Image
Introduction ffmpeg is a popular library that provides APIs for extracting information and manipulating videos. It supports various programming languages such as JavaScript , Ruby , and more. In this article, I'll give you a simple example of how to use ffmpeg to create thumbnails from videos and resize videos in NodeJS with TypeScript . Prerequisites Before we start, you need to install ffmpeg . The installation process depends on your operating system. If you're using Ubuntu , it's straightforward: sudo apt install ffmpeg Next, set up your NodeJS Typescript project. After that, install the package ` fluent-ffmpeg `. This package will serve as the interface for interacting between NodeJS and the previously installed ` ffmpeg `. yarn add fluent-ffmpeg Source Code Update the ` main.ts ` file with the following content: import * as ffmpeg from 'fluent-ffmpeg' const srcVideo = 'path/test.mp4' const outputVideo = 'path/test-resized.mp4...

Deploying a Python Flask Server to Google Kubernetes Engine

Image
Introduction In this article, I will guide you through deploying a Python Flask Server to Google Kubernetes Engine (GKE) . Previously, I wrote an article about deploying a NodeJS Application to GKE , which you can refer to for some basic information before continuing. Steps to Follow The process is quite similar to deploying a NodeJS Application and includes the following steps: Create a Python Flask Server Build a Docker image Push the Docker image Deploy the Docker image to GKE You will notice that when working with Kubernetes , the main difference is in the step where you build the Docker image . Depending on the application you need to deploy, there are different ways to build the Docker image . However, the common point is that once you build the Docker image , you have completed almost half of the process. This is because the subsequent steps involving Kubernetes are entirely the same. Detailed Process 1. Create a Python Flask Server In this step, you can either use an exist...