惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
T
The Blog of Author Tim Ferriss
H
Help Net Security
博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
博客园 - 聂微东
A
About on SuperTechFans
大猫的无限游戏
大猫的无限游戏
P
Proofpoint News Feed
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
酷 壳 – CoolShell
酷 壳 – CoolShell
G
Google Developers Blog
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
B
Blog
Engineering at Meta
Engineering at Meta
V
V2EX
Hugging Face - Blog
Hugging Face - Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Production-Ready Logging: An Agnostic ELK Stack Setup for...
Pau Dang · 2026-06-01 · via DEV Community
Cover image for Production-Ready Logging: An Agnostic ELK Stack Setup for Node.js (with a 512MB RAM Local Constraint)

Pau Dang

The Logging Nightmare

Deploying microservices across Multi-Cloud environments using tools like Terraform is an exhilarating milestone. But the moment something breaks, that excitement quickly turns into a nightmare.

  • The SSH Grind: If you find yourself SSH-ing into disparate instances just to run tail -f and grep through scattered log files, you're doing it wrong.
  • The Agnostic Approach: The industry standard demands Centralized Logging, but chaining your application to vendor-specific solutions like AWS CloudWatch or GCP Cloud Logging limits your architectural freedom. Implementing a true "Cloud-Agnostic" ELK stack gives you back control over your observability data.

Clean Architecture & The Non-Blocking Logger Factory

Building this robust observability pipeline requires adhering to Clean Architecture principles, specifically through a Non-Blocking Logger Factory.

  • Standardized Interface: By wrapping modern logging libraries like Winston or Pino, we standardize our application's logging interface.
  • The Secret Sauce: The winston-elasticsearch transport module buffers your logs and pushes them directly to your Elasticsearch cluster in the background.
  • Non-Blocking: This architectural choice is crucial: it ensures that high-volume log streaming happens without blocking the Node.js event loop.

Here is how the data flows through the system:

Resilience Fallback (The Failsafe)

A centralized system introduces a dangerous dependency. Your logging infrastructure must never be the reason your application crashes.

  • The Threat: If the remote Elasticsearch cluster is unreachable due to network partitions or rate limits, a poorly configured logger will throw uncaught exceptions, bringing down the app.
  • The Solution: We implement a strict Resilience Fallback (Failsafe) mechanism. The transport module safely catches the connection errors and seamlessly falls back to standard output (console), guaranteeing continuous operation.

The 512MB Local-Test Challenge

While this setup is a powerhouse in production, it presents a massive Developer Experience (DX) challenge locally. Elasticsearch is notorious for claiming 4GB to 8GB of RAM. Spinning up ELK locally on standard laptops is a guaranteed way to freeze the OS.

The "Aha!" Moment for Local Dev: We can tame the JVM by strictly limiting its memory footprint in the docker-compose.elk.yml configuration:

version: '3.8'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.10.0
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=false
      - ES_JAVA_OPTS="-Xms512m -Xmx512m"

  • Limiting Heap Size: ES_JAVA_OPTS="-Xms512m -Xmx512m" limits the Elasticsearch heap size to exactly 512MB, keeping your local dev environment snappy.
  • Frictionless Auth: Setting xpack.security.enabled=false removes the friction of managing certificates and passwords on your local machine.

Cloud Deployment Strategy

When transitioning to Production, your strategy must shift dramatically:

  • Managed Services: The strongly recommended approach is to leverage Managed Services like AWS OpenSearch or Elastic Cloud.
  • Self-Hosted Reality: If you must Self-Host on EC2 or GCP, you need at least 4GB of RAM (e.g., t3.medium/e2-medium). You must enable xpack.security, enforce TLS, and strictly firewall port 9200 from the public internet.

Conclusion

Achieving a balance between robust production observability and a frictionless, lightweight developer experience is the hallmark of mature software engineering.

I'd love to hear how you handle logging in your own microservices—drop a comment below! If you want to explore a project structure that supports this architecture out-of-the-box, check out the official docs for the Node.js Quickstart Generator - Observability (ELK Stack).

Try it yourself: