Skip to content

Instantly share code, notes, and snippets.

View jgcmarins's full-sized avatar

João Marins jgcmarins

View GitHub Profile

Node.js API Performance Playbook

Goal

Maximize throughput and reduce latency without changing infrastructure.

This playbook documents practical patterns that scaled an API from 100 req/s → 50,000 req/s on the same machine and database.


Node.js API Performance Optimization — Technical Specification

Overview

This document outlines performance optimization best practices for Node.js APIs based on real-world improvements where throughput increased from 100 req/s to 50,000 req/s on the same infrastructure (same machine and database).

No changes were made to:

  • Programming language
  • System architecture
@jgcmarins
jgcmarins / Dockerfile
Created June 30, 2025 14:32
Node.js Dockerfile for perfomance
FROM node:22.16-alpine AS builder
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build
RUN rm -rf node_modules && yarn install --production --frozen-lockfile
FROM alpine AS runtime
WORKDIR /app
@jgcmarins
jgcmarins / .env
Last active January 13, 2025 16:51
WordPress setup with docker-compose and traefik
MYSQL_ROOT_PASSWORD=
MYSQL_DATABASE=
MYSQL_USER=
MYSQL_PASSWORD=
@jgcmarins
jgcmarins / hybridRouter.tsx
Created August 26, 2024 13:56
router abstraction to work on both Next.js Apps and React Apps with react-router-dom
/* eslint-disable react-hooks/rules-of-hooks */
// 24:33 error React Hook "useNextRouter" is called conditionally. React Hooks must be called in the exact same order in every component render react-hooks/rules-of-hooks
// 25:43 error React Hook "useReactRouterNavigate" is called conditionally. React Hooks must be called in the exact same order in every component render react-hooks/rules-of-hooks
// 43:35 error React Hook "useNextPathname" is called conditionally. React Hooks must be called in the exact same order in every component render react-hooks/rules-of-hooks
// 44:37 error React Hook "useReactRouterLocation" is called conditionally. React Hooks must be called in the exact same order in every component render react-hooks/rules-of-hooks
'use client';
import { usePathname as useNextPathname, useRouter as useNextRouter } from 'next/navigation';
import {
@jgcmarins
jgcmarins / setup-env.ts
Created April 24, 2024 20:44
vitest config with setup and process.env mock
// https://github.com/vitest-dev/vitest/issues/1575#issuecomment-1439286286
export const setup = () => {
process.env.TZ = 'UTC';
process.env.NODE_ENV = 'test';
// add process.env mocks
};
@jgcmarins
jgcmarins / fix.md
Last active March 17, 2024 12:32
brew mongodb-community error

check mongod process

sudo lsof -iTCP -sTCP:LISTEN -n -P

kill the process

sudo kill <mongod_pid>
@jgcmarins
jgcmarins / serverless-api-gateway.yml
Created February 15, 2024 13:51
Multiple Lambdas with a single API Gateway
# serverless-api-gateway.yml
service: central-api-gateway
provider:
name: aws
runtime: nodejs14.x
stage: dev
region: sua-região
resources:
@jgcmarins
jgcmarins / index.js
Created January 10, 2024 22:51
Aleph Tech Interview Problem
/**
Given an integer array arr of distinct integers and an integer k.
A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of the game, we compare arr[0] with arr[1], the larger integer wins and remains at position 0, and the smaller integer moves to the end of the array. The game ends when an integer wins k consecutive rounds.
Return the integer which will win the game.
It is guaranteed that there will be a winner of the game.
Example 1:
Input: arr = [2,1,3,5,4,6,7], k = 2
Output: 5
@jgcmarins
jgcmarins / xlsxToPdfChatGPT.js
Created November 8, 2023 19:15
Chat GPT code to generate pdf from xlsx
const fs = require('fs');
const { PDFDocument, rgb } = require('pdf-lib');
const ExcelJS = require('exceljs');
// Function to convert XLSX to PDF
async function convertXlsxToPdf(inputXlsxPath, outputPdfPath) {
// Create a new PDF document
const pdfDoc = await PDFDocument.create();
// Load the XLSX file
const workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile(inputXlsxPath);