💡 How to Keep Your Node.js Cron Jobs Alive — Even When the Server Crashes Ever had your Node.js server crash and suddenly your cron jobs stopped running? It’s one of those “oh no” moments we all hit eventually. 😅 Here’s what really happens: Most of us set up cron jobs inside the Node app (using node-cron, agenda, etc.). But when the app crashes or restarts, those scheduled tasks die with it. So how do we fix it? 🚀 3 battle-tested approaches: 1️⃣ Use a Process Manager (PM2 / Docker) Let PM2 auto-restart your Node process if it crashes. Simple setup Great for small deployments Still pauses jobs during restarts 2️⃣ Run Cron Jobs Externally (Best Practice) Move cron logic outside your main server. Use a separate worker process (worker.js) Or a Linux cron / Kubernetes CronJob / AWS CloudWatch Event Keeps jobs running even if your web app crashes 3️⃣ Use a Managed Scheduler If you’re in the cloud: AWS Lambda + CloudWatch Events Google Cloud Scheduler Temporal.io, BullMQ, or Agenda with Redis These run independently and reliably. 💡 Bonus tip: If multiple app instances are running, use a distributed lock (e.g. Redlock + Redis) so only one instance executes the job at a time. ✅ My Recommendation: Keep your cron logic separate from the main API. Use PM2 (or Docker) to keep both the API and worker alive. Add a Redis lock if scaling horizontally. This setup has saved me (and my teams) from so many “why didn’t the job run?” mysteries. 😎 How are you managing your cron jobs in production? Curious to hear other setups. 👇 #NodeJS #Backend #DevOps #PM2 #CronJobs #SoftwareEngineering #WebDevelopment
How to Keep Node.js Cron Jobs Running After Server Crash
More Relevant Posts
-
🔷 Docker Compose — Running Multi-Container Apps the Easy Way Ever had to run multiple containers — like a web app, a database, and a cache — each with its own long docker run command? That’s exactly what Docker Compose was made for. 🔹 What it is: Docker Compose lets you define and run multi-container applications using one simple YAML file — usually named docker-compose.yml. 🔹 Example setup: version: "3" services: web: image: nginx ports: - "8080:80" redis: image: redis Run everything with just: docker compose up -d Now both containers start, share a network, and can talk to each other automatically. 🔹 Why it’s awesome: ▸ One command starts your whole stack. ▸ Automatic networking — services reach each other by name. ▸ Perfect for dev and test environments. 🔹 Common commands: docker compose ps # List containers docker compose down # Stop and clean up docker compose logs web # View logs for one service 🔸 Think of Docker Compose as a “project manager” for containers — it knows what to start, how to connect them, and how to stop everything neatly. 🔸 Question: Have you tried Docker Compose yet, or do you still start each container manually? #Docker #DevOps #Containers #DockerImage #Containerization #TechAnalogy #SoftwareDevelopment #CloudNative #Coding #DevOpsJourney
To view or add a comment, sign in
-
🚀 Just automated my deployment from GitHub to Azure! I'm excited to share that I've successfully set up a CI/CD pipeline for my Node.js API server using GitHub Actions. Here's what the pipeline does on every push to the main branch: -> 1. Build & Test: Spins up an Ubuntu runner, installs Node.js v22, and all project dependencies. -> 2. Quality Assurance: Runs the test suite using Jest to ensure nothing breaks. -> 3. Deploy: Automatically deploys the built artifact to my Azure Web App, ensuring a smooth and consistent release process. This automation enforces code quality, reduces manual deployment errors, and allows me to ship features faster. 💻⚙️ Tech Stack: GitHub Actions, Azure Web Apps, Node.js, Jest. #CI/CD #GitHubActions #Azure #DevOps #NodeJS #Automation #SoftwareEngineering #CloudComputing
To view or add a comment, sign in
-
It is the year 2026, stop saying "It works on my machine!" 🛑 😂 If you're still fighting environmental conflicts, struggling with slow developer onboarding, or dealing with tricky deployments, it's time for an upgrade. Let's talk about Docker and how it solves the biggest pain point in software development. What is Docker? (The Shipping Container Analogy) Docker is the shipping container for your software. Just like a physical container can hold anything (electronics, clothes, food) and be shipped anywhere, a Docker container holds your entire application, its dependencies (Node.js, MongoDB, Redis), and its configuration, and can run flawlessly anywhere, from your laptop to the cloud server. Think of it: Instead of installing three separate systems (Node, Mongo, Redis), Docker creates three isolated, pre-configured "boxes" (containers). You run one command, and they all start working together. Understanding the Key Docker Files 1. Dockerfile (The Recipe): The blueprint for building one service (e.g., your backend API). It defines the base image, copies the code, installs dependencies, and specifies the start command. 2. docker-compose.yml (The Orchestra): The master plan for your entire application stack. It defines how your multiple containers (Backend, Database, Cache) are linked, what ports they use, and how they share data. 3. .dockerignore (The Exclusions): A simple list that tells Docker what local files to ignore when building the image (e.g., node_modules, .git, temporary logs). This keeps your final image clean and secure. Your 3 Daily Commands (The Automation) docker-compose up -d (Start the whole stack in the background) docker-compose logs -f backend (Stream logs for troubleshooting) docker-compose down (Stop and clean up the containers) If you're building a multi-service app (like a web app with a database and cache), Docker is non-negotiable for efficiency. What was the biggest headache Docker solved for your team? Share your experiences below! 👇 #Docker #DevOps #Containerization #SoftwareDevelopment #TechTips
To view or add a comment, sign in
-
-
🚀 𝐃𝐞𝐩𝐥𝐨𝐲𝐢𝐧𝐠 𝐚 𝐑𝐞𝐚𝐜𝐭 + 𝐒𝐩𝐫𝐢𝐧𝐠 𝐁𝐨𝐨𝐭 𝐀𝐩𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐨𝐧 𝐀𝐖𝐒 𝐄𝐂𝐒 𝐰𝐢𝐭𝐡 𝐍𝐠𝐢𝐧𝐱 𝐑𝐞𝐯𝐞𝐫𝐬𝐞 𝐏𝐫𝐨𝐱𝐲 We recently implemented a containerized web architecture on AWS ECS (Fargate) that combines a React frontend, an Nginx reverse proxy, and a Spring Boot backend — all fully automated, scalable, and production-ready. 🧩 Architecture Overview Browser → ALB → Nginx (ECS) → Spring Boot (ECS) → Database (RDS/DynamoDB) The React app is built and served through Nginx inside a container, while API traffic is reverse-proxied to our Spring Boot backend running as a separate ECS service. ⚙️ Key Setup Details 1️⃣ React Build We generate an optimized static bundle using npm run build. These files are copied into the Nginx image and served from /usr/share/nginx/html. 2️⃣ Nginx Reverse Proxy Our Nginx config serves static assets and proxies /api/* requests to the backend ECS service: location /api/ { proxy_pass http://backend-service:8080; } 3️⃣ Backend Service Spring Boot runs on ECS (or Fargate), behind an Application Load Balancer (ALB) for scaling and fault tolerance. 4️⃣ Networking & Routing The ALB directs web traffic to Nginx containers and internal API traffic to backend containers. Service discovery allows Nginx to seamlessly reach backend tasks. 5️⃣ Security & Observability • HTTPS via AWS Certificate Manager (ACM) • Monitoring via CloudWatch • Controlled access using Security Groups & IAM Roles 🌟 Why This Architecture Works ✅ Fully containerized & scalable with ECS Fargate ✅ Nginx handles both static content & API routing ✅ Clean separation between frontend and backend services ✅ Easy integration with AWS CI/CD (CodePipeline, ECR) ✅ Supports blue/green and zero-downtime deployments 💡 Bonus Tip: For static-heavy apps, React can also be hosted on S3 + CloudFront while keeping APIs on ECS — reducing cost and boosting performance globally. This setup delivers the best of both worlds — the simplicity of Nginx for frontend delivery and the robustness of Spring Boot microservices — all powered by AWS. 🌩️ #AWS #ECS #Nginx #SpringBoot #ReactJS #CloudArchitecture #DevOps #Fargate #Microservices #CloudComputing
To view or add a comment, sign in
-
-
🔷 Docker Networking — How Containers Talk to Each Other Ever wondered how multiple containers — like a web app and a database — actually see each other? That’s where Docker networking comes in. 🔹 Default networks created by Docker: ▸ When you install Docker, it automatically sets up three: ▸ bridge → default network for containers. ▸ host → shares the host’s network directly. ▸ none → no network at all (fully isolated). 🔹 Most common case — bridge network ▸ When you run: docker run -d --name web nginx ▸ Docker connects it to the bridge network and gives it an internal IP like "172.17.x.x". 🔹 Connecting containers together: ▸ Create your own network so they can reach each other by name: docker network create mynet docker run -d --network=mynet --name redis redis docker run -d --network=mynet --name webapp kodekloud/simple-webapp ▸ Now webapp can talk to redis just by using its name — no IPs needed! 🔹 Quick summary: ▸ bridge → default, isolated. ▸ host → shares host ports (no mapping). ▸ none → no connectivity. ▸ user-defined → lets containers communicate by name. 🔸 Think of Docker networks like Wi-Fi groups — containers on the same network can see each other; others can’t. 🔸 Question: Have you ever created your own Docker network, or do you usually stick with the default bridge? #Docker #DevOps #Containers #DockerImage #Containerization #TechAnalogy #SoftwareDevelopment #CloudNative #Coding #DevOpsJourney
To view or add a comment, sign in
-
Node.js Backend Performance Optimization: 5 Serverless Strategies for 2025 - Expert Developers' Insights The world of backend development is constantly evolving, and with the rise of serverless architectures, Node.js developers have a powerful toolkit at their disposal. But power without precision is, well, just power. Optimizing your Node.js backend... Read more: https://lnkd.in/giJaJRM8 #Node_js #Serverless #Performance_Optimization #Backend #Expert_Developers #AWS_Lambda #Azure_Functions #Google_Cloud_Functions
To view or add a comment, sign in
-
-
Serverless Node.js with Kubernetes: A 2025 Guide for Expert Developers The landscape of backend development is constantly evolving, demanding solutions that are both scalable and cost-effective. In 2025, serverless Node.js orchestrated by Kubernetes is emerging as a dominant paradigm. This approach allows developers... Read more: https://lnkd.in/eygxv2yJ #Serverless #Node_js #Kubernetes #Expert_Developers #Backend_Development #Microservices #Cloud_Native #Scalability #Cost_Optimization
To view or add a comment, sign in
-
-
⚖️ Backend Concept Explained Simply: Load Balancing When your app grows, one server isn’t always enough. Too many users = too many requests = one tired server 😵💫 That’s where Load Balancing comes in. Imagine this 🍔: You run a busy restaurant with 3 chefs in the kitchen. If all orders go to one chef, he’ll burn out. So, you have a smart waiter who distributes orders evenly between the chefs. That waiter = Load Balancer That kitchen = Your servers 💡 In simple terms: Load balancing means distributing incoming traffic across multiple servers, so no single server gets overwhelmed. ⚙️ Benefits: ✅ Better performance — faster response times ✅ High availability — if one server fails, others handle the load ✅ Scalability — easily add or remove servers as needed 🧠 Example (in real life): * AWS Elastic Load Balancer automatically spreads traffic across EC2 instances * NGINX or HAProxy can act as software load balancers for backend apps ✨ In short: Load Balancing = “Sharing the work so nothing breaks under pressure.” #Tech #Programming #Developer #SoftwareEngineering #WebDevelopment #Coding #BackendDevelopment #FullStackDeveloper #NodeJS #MERNStack #ServerSide #LoadBalancing #SoftwareTips #DevCommunity
To view or add a comment, sign in
-
-
🚀 Backend Upgrade in Progress! Here’s what I improved 👇 ✅ Added structured middleware — CORS with env-based origin, body size limits, cookie parsing, and static assets ✅ Deferred server startup until MongoDB connects to ensure reliability ✅ Introduced utility helpers like ApiResponse, ApiError, and asyncHandler for consistent error and response patterns Key Learnings: 🔹 Secure and environment-driven configuration 🔹 Predictable request lifecycle 🔹 Cleaner, more maintainable controller logic 🔹 Error Handling 💡 Takeaway for others: Centralize middleware early, wrap async handlers to avoid repetitive try/catch blocks, and standardize responses — it’ll make your backend far easier to debug and scale! Check out all my Backend Practices here 👇 🔗 GitHub Repo: https://lnkd.in/dAa5nBid #NodeJS #MongoDB #Backend #Mongoose #WebDev #Learning #FullStack
To view or add a comment, sign in
-
-
🚀 How I set up a CI/CD pipeline for a Node.js app using AWS When I first started working on backend projects, writing the code was the fun part, but deploying it manually again and again? Not so much 😅 That’s when I realized the real power of CI/CD automating the entire journey from commit → build → deploy. Here’s how I built a clean, AWS native pipeline for one of my Node.js apps 👇 ⚙️ Tech Stack I used 1. AWS CodePipeline → the brain of the workflow. 2. AWS CodeBuild → installs dependencies, runs tests, and builds. 3. AWS S3 → stores the build artifacts. 4. AWS Elastic Beanstalk / ECS → handles deployment automatically. 📗How it flows 1. Push code to GitHub (or CodeCommit). 2. CodePipeline picks it up instantly. 3. CodeBuild runs npm install, npm test, and npm run build. 4. The artifact is deployed to Elastic Beanstalk or ECS. 5. App goes live, no manual steps, no downtime. 🔹 Some lessons learned 1. Always define a buildspec.yml (it’s your build blueprint). 2. Keep environment variables in Parameter Store or Secrets Manager. 3. Use CloudWatch Logs; it saves hours when debugging. 4. Stick to least-privilege IAM roles (security > convenience). 5. Add a staging environment before pushing to production. 💬 Why I love this setup: It saves time, prevents human errors, and allows me to ship updates confidently. Once the pipeline is live, it feels like having an invisible teammate who deploys for you. 📝 Note: Enable build caching in CodeBuild, which cuts build time by nearly 40%. #AWS #NodeJS #DevOps #BackendDevelopment #CodePipeline #CICD #CloudEngineering
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Great advice 💯