Skip to content

Latest commit

 

History

History
213 lines (160 loc) · 11.3 KB

File metadata and controls

213 lines (160 loc) · 11.3 KB

🛡️ Smart Microservice Health Guardian — FAQ & Defense Guide

This document contains a comprehensive list of Frequently Asked Questions (FAQs) and a "Defense Guide" to help answer questions from judges or clients confidently.


🌟 Core Concepts & Innovation

1. What is the main innovation here?

Answer: Our system learns the normal behavior of each service automatically using statistics. It detects slow failures early, understands dependencies, and prevents cascading breakdowns — all in real-time without complex setup.

2. How is this different from existing tools like Prometheus or Grafana?

Answer: Those tools often rely on manual static thresholds (e.g., "Alert if CPU > 80%") which generates noise. Our system uses dynamic baselines, trend prediction, and dependency awareness. We warn before the failure happens, not just after.

3. Why is real-time monitoring important?

Answer: Most failures start small and escalate quickly. Our 1-second evaluation cycle helps teams take action immediately, avoiding costly downtime.

4. What is the business value? Why would companies pay for this?

Answer: Reliability equals Revenue.

  • Reduces Downtime
  • Minimizes User Complaints
  • Lowers Engineer Stress
  • Prevents Revenue Loss

5. Can you show a real incident where this helps?

Answer: Imagine an Auth Service where latency slowly rises from 50ms to 500ms.

  • Without us: No alert until it hits a hard limit or crashes. Users are frustrated.
  • With us: The system detects the "Rising Trend" (>15%) early, sends a warning, and the issue is fixed before any outage occurs.

🧠 Intelligence & "AI"

1. Does it use AI? What exactly is the "AI" part?

Answer: There is NO heavy AI model (like LLMs). Instead, we use "Statistical AI" (Math-based Intelligence):

  • Mean & Standard Deviation: To understand "normal".
  • Z-Score Thresholds: To detect anomalies.
  • Linear Regression: For trend analysis.

This approach is faster, lighter, and more reliable than black-box AI models.

2. Why is a statistical approach enough?

Answer: Microservice health metrics follow predictable patterns. Basic math is sufficient to detect abnormal changes without the overhead of heavy Machine Learning models. It’s smarter because it’s faster.

3. How does the Guardian decide Warning or Critical states?

  1. Dynamic Baselines:
    • Mean + 2.5 StdDev → Warning 🟡
    • Mean + 3.5 StdDev → Critical 🔴
  2. Trend Analysis: If latency rises >15% in a short window → Early Warning.
  3. Heartbeat Check: No heartbeat for >60 seconds → Critical.
  4. Debounce: Alerts are only sent if the issue persists (prevents noise).

📉 Math & Metrics Explained (Simple Terms)

1. Why do we need a 1.5-minute "Learning Phase"?

Think of this like a runner warming up.

  • The Problem: When you first wake up, you are groggy and slow. If someone measured your sprint speed right when you woke up, they would think you are a terrible runner.
  • The Solution: We give the service 90 seconds (1.5 min) to "wake up," connect to the database, and load its files.
  • Why it makes sense: If we started alerting immediately, we would get False Alarms because the service is naturally slow during startup. We wait for it to "settle down" to find its true normal speed.

2. Why does latency "boom" (spike) when a service starts?

This is called a "Cold Start."

  • Empty Caches: The service hasn't saved any shortcuts yet, so it has to do the hard work for every request.
  • Connection Handshakes: It has to introduce itself to the database ("Hi, I'm Auth Service, here is my password") which takes time.
  • Code Optimization: Modern languages (like Node.js or Java) actually optimize the code while it runs. The first few times a function runs, it's slow. After 100 times, the computer finds a faster way to run it.

3. The Dictionary (Simple Terms)

What is Latency?

  • Simple: Speed. (Time to wait).
  • Example: You order a coffee.
    • If you get it in 2 minutes, Latency = 2m.
    • If you get it in 10 minutes, Latency = 10m.
  • Goal: We want this number to be LOW.

What is a Baseline?

  • Simple: "The Normal."
  • Example: You usually sleep 8 hours. That is your baseline. If you sleep 12 hours one day, that is abnormal.

What is a Dynamic Baseline?

  • Simple: "The Moving Normal."
  • Scenario: On weekdays, your baseline sleep is 8 hours. On weekends, your baseline is 10 hours.
  • Why we use it: A "Static" baseline says "Anything over 8 hours is bad!" (which is wrong on weekends). A Dynamic baseline learns: "Oh, it's Saturday? 10 hours is fine. No alert needed."
  • In our app: It learns that "50ms is normal for Auth Service" but "200ms is normal for Storage Service."

What is Mean?

  • Simple: The Average.
  • Formula: (Sum of all numbers) / (Count of numbers)
  • Example: Latencies are 10, 20, 30. Mean = 20.

What is Standard Deviation (StdDev or σ)?

  • Simple: The "Wiggle Room" or "Consistency."
  • Low StdDev: You run a mile in 6 mins, 6:01, 5:59. (You are consistent).
  • High StdDev: You run a mile in 6 mins, then 10 mins, then 4 mins. (You are chaotic/unstable).
  • Why it matters: If a service usually has Low StdDev (very stable) and suddenly spikes, we know something is wrong immediately.

4. The Formulas (Simplified)

The Warning Threshold (Yellow Alert 🟡)

  • Concept: "This is getting weirdly slow."
  • Formula: Mean + (2.5 × StdDev)
  • English: Take the Average, add 2.5 times the "Wiggle Room". If the current speed is slower than that, send a Warning.

The Critical Threshold (Red Alert 🔴)

  • Concept: "Okay, this is definitely broken."
  • Formula: Mean + (3.5 × StdDev)
  • English: Take the Average, add 3.5 times the "Wiggle Room". This is extremely far away from normal.

The Z-Score (The "Severity Score")

  • Concept: How we calculate the color.
  • Formula: (Current Latency - Mean) / StdDev
  • English: "How many 'wiggles' away from normal is this request?"
    • Score < 2.5 = Green (Normal)
    • Score > 2.5 = Yellow (Warning)
    • Score > 3.5 = Red (Critical)

🏗️ Architecture & Scalability

1. Of those 6 command windows, how many are actual servers?

Answer: You have 4 actual backend servers monitored by the Guardian:

  1. Backend (Port 3000)
  2. Auth Service (Port 3001)
  3. Booking Service (Port 3002)
  4. Storage Service (Port 3003)

The other two are the Frontend (Development Server) and the Traffic Generator (Script).

2. Can this scale for large microservice systems?

Answer: Yes. The system is lightweight. The Agent stores metrics in memory and sends data in batches (every 2 seconds) using async non-blocking I/O. It adds less than 1ms overhead to the application.

3. What happens if the Health Guardian itself crashes?

Answer: Monitoring stops temporarily, but the Client Services (Auth, Booking, etc.) keep running. The Health Agent uses try/catch blocks, so if the Guardian is down, the agent quietly skips sending metrics. It is NOT a single point of failure.

4. Why MongoDB instead of a time-series DB like Prometheus?

Answer: For the MVP, MongoDB is flexible and allows us to store Users, Baselines, Logs, and Metrics in one place. For production, the architecture allows swapping the storage layer with InfluxDB or Prometheus easily.

5. What happens to data after 24 hours? Does the DB grow forever?

Answer: Currently, we store everything. In production, we would implement a TTL (Time-To-Live) Index to automatically delete raw data older than 7 days, keeping only daily summaries for long-term trends.


🔧 Implementation & Integration

1. How will clients "wrap" their applications?

Answer: "Wrapping" means adding our Health Agent SDK. It requires just 3 lines of code:

import { createHealthAgent } from './health-agent.js';
const agent = createHealthAgent('My-App-Name');
app.use(agent.middleware());

This automatically starts timers, checks latency, captures errors, and sends metrics. No rewrite needed.

2. Can this monitor Python or Java services?

Answer: Yes, but it requires a language-specific wrapper. The Backend API accepts JSON metrics from ANY language. Currently, we have a Node.js Agent. Future plans include Python, Java, and Go Agents.

3. Where does JWT work in the application?

Answer: JWT acts as a digital ID card.

  1. Admin logs in → Backend verifies credentials → Issues JWT.
  2. Frontend stores JWT and attaches Authorization: Bearer <token> to every request.
  3. This proves the user is allowed to view the dashboard.

4. How do you secure communication between services?

Answer: Currently, it uses internal network traffic. In production, we would implement API Keys and mTLS (Mutual TLS) to ensure only authorized services can send metrics.


🚨 Monitoring & Alerts

1. When exactly does Telegram send Warning or Critical messages?

  • CRITICAL: Service crashes (No heartbeat > 60s) → Waits 30s to confirm → Immediate Alert.
  • STARTUP: Service starts → Immediate Alert.
  • WARNING: Service enters warning state (slowness) → Sends one message every 15 minutes (Rate Limited/Debounced).

2. How will others use the Telegram Bot?

Answer: It is a "Self-Service Configuration":

  1. Client creates their own bot using BotFather.
  2. Client adds the bot to their team group.
  3. Client pastes the Bot Token and Chat ID into our Dashboard Settings.
  4. The Guardian uses their bot to send alerts only to them.

3. If 'Auth Service' is down, how does the dashboard show it?

Answer:

  • Auth Service: 🔴 Critical
  • Booking Service: ⚠️ At Risk (Not Error) The system understands Dependencies. It highlights the Root Cause (Auth) so admins don't waste time debugging the Booking service.

4. Can your system detect logical errors (e.g., wrong calculation)?

Answer: No. This is an Infrastructure Monitor. It detects slowness, crashes, and HTTP errors. It does not validate business logic or output correctness; that requires functional testing.


🚀 Operations & Future

1. What is the login technique?

Answer: Single Admin User.

  • Default: admin@healthguardian.com / admin123
  • Technique: Email/Password + bcrypt hashing + JWT Session.

2. If I change the password in seedAdmin.js, will it become default?

Answer: Yes, but ONLY if the admin user doesn't already exist in the database. If the user exists, the script does nothing. Best practice is to set ADMIN_PASSWORD in the .env file.

3. What is the difference between 'Latency' and 'Throughput'?

  • Latency: Time taken to complete ONE request (Speed).
  • Throughput: Number of requests per second (Volume).

4. What's next for the project?

Answer:

  1. Docker/Kubernetes Integration: For automated container restarts.
  2. RBAC: Role-Based Access Control for multiple users.
  3. More Channels: Slack, Email, and PagerDuty integration.