Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungConnect Claude to Perplexity AI Pro with Zero Search API Fees(24.09.2026 um 09:57 Uhr)
Sichere ProgrammierungInvestigating Fraud with a Graph, Not Just a Prompt(24.09.2026 um 10:01 Uhr)
Sichere ProgrammierungA .docx does not store where its pages end(24.09.2026 um 10:01 Uhr)
Sichere Programmierung9 Best Enterprise AI Gateways With SSO, RBAC, and Audit Logs (2026)(24.09.2026 um 10:01 Uhr)
Sichere ProgrammierungThe Signal Contract for a 5-Minute TWAP Market(24.09.2026 um 10:03 Uhr)
Sichere ProgrammierungRemoteMac(24.09.2026 um 10:06 Uhr)
Sichere ProgrammierungDesigning a Batch Move That Handles Partial Failure(24.09.2026 um 10:07 Uhr)
Sichere ProgrammierungThe Model Was Never the Problem(24.09.2026 um 10:07 Uhr)
Sichere ProgrammierungConnect Claude to Perplexity AI Pro with Zero Search API Fees(24.09.2026 um 09:57 Uhr)
Sichere ProgrammierungInvestigating Fraud with a Graph, Not Just a Prompt(24.09.2026 um 10:01 Uhr)
Sichere ProgrammierungA .docx does not store where its pages end(24.09.2026 um 10:01 Uhr)
Sichere Programmierung9 Best Enterprise AI Gateways With SSO, RBAC, and Audit Logs (2026)(24.09.2026 um 10:01 Uhr)
Sichere ProgrammierungThe Signal Contract for a 5-Minute TWAP Market(24.09.2026 um 10:03 Uhr)
Sichere ProgrammierungRemoteMac(24.09.2026 um 10:06 Uhr)
Sichere ProgrammierungDesigning a Batch Move That Handles Partial Failure(24.09.2026 um 10:07 Uhr)
Sichere ProgrammierungThe Model Was Never the Problem(24.09.2026 um 10:07 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Struggling with Slow AI Responses: Building a Streaming Chat UI with SSE

I was building an internal documentation assistant for my team. You know the drill: a chatbot that answers questions about our codebase, pulled from a vector database and then sent to an LLM. I set up the backend in Python, used a decent…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

I was building an internal documentation assistant for my team. You know the drill: a chatbot that answers questions about our codebase, pulled from a vector database and then sent to an LLM. I set up the backend in Python, used a decent model via an API (shoutout to interwestinfo.com for the reliable endpoint), and wired it all up. Simple, right?



Then came the first real test: someone asked a question that required a long, thoughtful answer. The response took over 30 seconds. The user stared at a blank chat bubble, refreshing the page, wondering if the app had crashed. Not a great experience.



I needed to stream the tokens back as they were generated, so the user could read along. This is the classic “chat UI” pattern. But implementing it turned into a rabbit hole of half-baked solutions.






What I Tried That Didn’t Work






1. Polling



My first idea: make the LLM call, store the partial result in Redis, and have the frontend poll every second. This was ugly. The prediction endpoint returned the full response eventually, so I needed to change the backend to write tokens piece by piece. Polling also meant 30-ish HTTP requests per message, which felt wasteful. And the UI was jerky – updates came in bursts, not smoothly.






2. WebSockets



WebSockets seemed like the obvious choice. I wrote a FastAPI WebSocket endpoint, opened a connection, and streamed tokens frame by frame. This worked… except for one thing: my deployment environment (a low-budget VPS behind a load balancer) had aggressive idle timeouts. The connection would drop after 60 seconds, and reconnecting with WebSockets required manual logic. Also, half the libraries in my stack didn't support WebSockets easily – my auth middleware, for instance, expected HTTP requests.



But the real pain: WebSockets are bidirectional. I didn't need bidirectional. I just needed the server to push data to the client. WebSockets felt like overkill.






3. Long Polling (Bad Idea)



Yeah, I tried that too. The server would hold the response open and flush chunks. But HTTP/1.1 connections have issues with that, and my framework (Flask at the time) didn't handle it gracefully without monkey-patching. I gave up after two hours of “connection closed” errors.






What Eventually Worked: Server-Sent Events (SSE)



I had used SSE before for real-time tweets, but never for AI streaming. SSE is a standard (part of HTML5) where the server sends a stream of events over a single, long-lived HTTP connection. The client uses the EventSource API. It’s unidirectional (server → client), which is exactly what I needed.



FastAPI supports SSE natively via StreamingResponse. Here’s the backend code that made my UX smooth again:




from fastapi import FastAPI, Request
from fastapi.responses import StreamingResponse
import asyncio

app = FastAPI()

async def generate_tokens(prompt: str):
# Assume get_llm_response is an async generator that yields tokens
# (e.g., using OpenAI's streaming API with `stream=True`)
async for token in get_llm_response(prompt, stream=True):
yield f"data: {token}\n\n"
await asyncio.sleep(0.01) # simulate latency
yield "data: [DONE]\n\n"

@app.post("/chat")
async def chat(request: Request):
body = await request.json()
prompt = body["message"]
return StreamingResponse(generate_tokens(prompt), media_type="text/event-stream")






The frontend became trivial:




const eventSource = new EventSource('/chat', {
method: 'POST',
body: JSON.stringify({ message: userInput })
// EventSource doesn't support POST by default?
});






Wait – that's the trickiest part. The EventSource API only supports GET requests. My chat endpoint needs a POST with the prompt. I could refactor to a GET with query params (ugly and limited). Instead, I used a workaround: I made a GET endpoint that accepts the prompt as a query parameter. Or, I wrote a small wrapper that uses fetch to POST and then reads the response body as a stream manually.



I went with fetch + ReadableStream for more control:




async function startStream(prompt) {
const response = await fetch('/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: prompt })
});

const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = '';

while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });

// Split by SSE format "data: ...\n\n"
const parts = buffer.split('\n\n');
buffer = parts.pop(); // keep incomplete chunk
for (const part of parts) {
const line = part.trim();
if (line.startsWith('data: ')) {
const token = line.slice(6);
if (token === '[DONE]') {
// stream finished
} else {
appendToken(token);
}
}
}
}
}






This works perfectly. No WebSocket library, no complex reconnection – just plain HTTP. If the connection drops (e.g., timeout), the fetch rejects, and I can retry with a new request. The UX is fluid: tokens appear as they're generated.






Lessons Learned & Trade-offs




  • SSE is simple for server-to-client streaming. If you need bidirectional (like a multiplayer game), WebSockets are better.

  • The EventSource API is limited to GET. Workaround: use fetch with a ReadableStream.

  • SSE works over HTTP/1.1 and HTTP/2. No special server config needed.

  • Browser support is universal (IE is dead, Edge and Safari work fine).

  • Backpressure: if the client is slow, the server just buffers – but with token streaming, tokens are small so that's rarely a problem.

  • Security: SSE connections are just HTTP; same CORS and auth rules apply. I passed a token in the POST body, not the URL.



One downside: SSE doesn't handle structured data as easily as WebSocket frames. But for plain text tokens, it's ideal.






What I'd Do Differently Next Time



I would skip the WebSocket experiment entirely. For chat apps, LLM streaming, or any real-time data that flows one way (e.g., notifications, logs), SSE is the right tool. Next time, I'd also build a small abstraction over the fetch + ReadableStream to handle reconnection automatically (exponential backoff, etc.).



Also, I'd check if my LLM provider supports SSE out of the box. Some do (OpenAI's data: [DONE] format is already SSE-compatible). Others, like the one I used from interwestinfo.com, return tokens via a custom endpoint – but I can wrap that as async generator easily.






Your Turn



Have you built a streaming AI UI? Did you use SSE, WebSockets, or something else? I’m curious how you handled reconnection and error states. Share your setup – I learn a lot from these discussions.

SOC Incident Playbook: Remote Code Execution (RCE) Defense
title: Detect Exploitation - Struggling with Slow AI Responses: Building a Streaming Chat UI with SSE
id: ecbfe94d-a2b0-4aad-9e8f-7d417145d0ab
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-24
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-24"
        description = "YARA Signature for "
    strings:
        $str = "Struggling with Slow AI Respon" ascii wide
    condition:
        any of them
}
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Struggling with Slow AI Responses: Build.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Struggling with Slow AI Responses: Building a Streaming Chat UI with SSE

Thematisch verwandte Begriffe: Struggling, with, Slow, Responses · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-97056 | SigNoz versions from v0.98.0 up to (but not including) v0.143.0, when co…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick