How would you design a system that parses incoming messages, sends them to backend code, intercepts responses, and sends them back to the UI using Pub/Sub?
1Times asked
Apr 2026Last seen
Apr 2026First seen
💡 Model Answer
A robust architecture for this requirement would consist of the following layers:
- Ingress – An API Gateway or HTTP endpoint receives raw messages from clients. It performs basic validation and forwards the payload to a message parser service.
- Parser Service – A stateless microservice that normalizes the message format, enriches metadata, and publishes the parsed event to a Pub/Sub topic (e.g., Google Pub/Sub or AWS SNS/SQS). This decouples ingestion from downstream processing.
- Worker Pool – Multiple worker instances subscribe to the Pub/Sub topic. Each worker executes the core backend logic (business rules, database access, external API calls). Workers are horizontally scalable and can be containerized (Docker/Kubernetes) for elasticity.
- Response Interceptor – After processing, workers publish a response message to a second Pub/Sub topic dedicated to UI updates. A dedicated interceptor service subscribes to this topic, aggregates responses if needed, and forwards them to the UI layer.
- UI Delivery – The UI receives updates via WebSocket, Server‑Sent Events, or a real‑time messaging SDK (e.g., Firebase Realtime Database). The interceptor can push messages directly to the client’s connection ID.
Key decisions: use asynchronous Pub/Sub to handle bursty traffic, implement idempotency keys to avoid duplicate processing, secure topics with IAM policies, and monitor latency with distributed tracing. This design ensures scalability, fault tolerance, and low latency for real‑time UI updates.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.
Get Assisting AI — Starts at ₹500