Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/694ab010-3e7c-8000-b0e8-b98c22b7a063
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: === ==== No—it should be the opposite: keep FastAPI stateless at the container level, and store state in external services. ==== ===== Your FastAPI container should be disposable. If ECS kills it and restarts it, you must not lose: ===== * conversation history * user identity / session context * RAG indexes / embeddings * document metadata So you store those outside the container: ===== A) Conversation memory ===== * Store per-user conversation turns in: - DynamoDB (simple and scalable), or - RDS Postgres (if you already run it), or - ElastiCache Redis (fast session cache, optional) Then each request includes a user_id (or session_id) and the API loads the last N turns. B) RAG documents / embeddings * Store files in S3 * Store vectors in a vector store: - Postgres + pgvector on RDS (common, robust) - OpenSearch vector engine (more ops) - A managed vector DB if you use one C) “Past used files from past” If you mean “the user uploaded files earlier, and later questions should use those same files,” that is exactly what S3 + metadata DB + vector store solves: * Uploaded file → S3 object * Extract text → chunk → embed → store vectors with user_id + file_id * Later queries: retrieve top-k by user_id scope ===== No. Avoid it. Use external state instead. ===== Then any FastAPI task can answer any request, which enables scaling and reliability. ==== This is a very common misunderstanding. ==== CORS is not about which users can use your UI. CORS is about which websites (origins) are allowed to call your API from a browser. ===== - Your UI has one domain (or a few): e.g. https://app.yourdomain.com ===== * You want any user on the internet to visit that domain and use the UI * But you do not want random other websites (origins) to call your API directly from their JavaScript So you restrict CORS to your UI’s domain, not to specific people. ====== - Allowed origin: https://app.yourdomain.com ====== * Users: unlimited (the public) * Blocked: https://evilsite.com calling your API from a browser If you truly have multiple UI domains (staging, prod), you add them: * https://app.yourdomain.com * https://staging.yourdomain.com ===== CORS does not replace authentication. ===== If your API is paid / sensitive, you still need auth (JWT/Cognito/API key/usage plans). CORS just prevents browser-based cross-site abuse. ==== You can run: ==== * Browser → ALB → Streamlit * Streamlit → ALB → FastAPI and skip API Gateway entirely. So the real question is: what does API Gateway give you that ALB alone does not? ===== API Gateway is a specialized “API front door” that provides API-focused capabilities that are harder (or impossible) to do cleanly with ALB alone: ===== # Authentication integrations * Native integrations with Cognito JWT authorizers, IAM auth, custom authorizers * Easier to standardize “who can call this API” # Throttling and quotas * Rate limit per client (and optionally usage plans, especially with REST API) * Prevents runaway costs (very relevant with LLM calls) # Request/response controls and API lifecycle * Versioning via stages (/prod, /v1) * Central API configuration independent of ALB listener rules # WAF attachment for API-specific protection * You can attach WAF to ALB too, but many teams prefer WAF policies at the API edge # Observability posture for APIs * API-oriented metrics and logs, easier “API product” management ===== - If this is a public, real product (unknown users, cost risk, need auth/limits): keep API Gateway → FastAPI. ===== * If this is internal or a demo (low risk): ALB-only is acceptable. ===== - Streamlit is a “website-like” workload: lots of small UI requests, internal paths, interactive behavior ===== * FastAPI is a “call center” workload: discrete API requests where you want policy controls (auth, throttling, quotas) Users should go to: * UI: ALB (or CloudFront) API calls should go to: * API Gateway (for control) → ALB → FastAPI ==== This matters because LLM-backed APIs are expensive compared to UI. ==== ===== Assume: ===== * Each container has enough CPU/memory to handle LLM calls well * You deploy 1 service with 1 container type Traffic: * 200 people open the UI (mostly idle browsing) * 20 people actually send chat messages Problem: * UI traffic forces you to scale containers to keep the UI snappy * But those same containers also include the backend runtime and secret access * You end up paying for LLM-capable containers even when people are just loading the UI Example: * UI load requires 6 tasks to keep responsiveness * You now have 6 “full stack” tasks running even though only 1–2 tasks worth of API compute is needed ===== Now: ===== * UI service: lightweight, can run 2–3 small tasks * API service: scales only when chat calls increase Example: * UI: 2 tasks (small CPU/mem) * API: 1 task normally, scales to 5 only if request rate spikes Benefits: # Lower cost * API tasks are larger (CPU/mem), scale only when needed # Higher reliability * UI spikes do not crash API * API spikes do not slow UI # Better security * Only API tasks can read secrets # Cleaner operations * You debug UI and API independently ===== - UI scaling metric: ALB request count / target response time ===== * API scaling metric: request rate to /api/chat, CPU, latency ==== ### ==== Yes—but do it with external state: * Conversation history in DynamoDB/RDS * RAG vectors in pgvector/OpenSearch * User/session IDs passed on each request ===== Yes. Restrict to your UI domain. That still supports unlimited users. ===== ===== If you want: ===== * throttling + quotas * auth (Cognito/JWT) * a clean API front door then yes. If you only want it to “route traffic,” then ALB alone is enough. If you tell me one thing—is your chatbot public (unknown users) or private (only you / internal)?—I will recommend the exact minimal security setup (Cognito vs simple token vs no auth) without adding unnecessary AWS complexity.
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)