Node.js MCQs - Real-Time, Messaging and APIs: WebSockets, Queues, gRPC (Set 6)

Node.js MCQs - Real-Time, Messaging and APIs: WebSockets, Queues, gRPC (Set 6) - CodingHumans

In senior Node.js interviews, the questions go past Express routes. They want to know how your services talk to clients and to each other. This set covers real-time connections (WebSockets, Socket.IO, Server-Sent Events), message queues like RabbitMQ and Kafka, and the API design topics that show up in system design rounds: rate limiting, idempotency, versioning, GraphQL and gRPC.

How to practise: read each question and tap the option you think is correct. You will see right away whether you got it, along with a short explanation, and your score is tracked at the bottom of the screen. This set has 15 questions.

Node.js MCQ series: Set 1 | Set 2 | Set 3 | Interview Preparation Hub

Topics covered in this set

  • WebSockets and Socket.IO
  • Server-Sent Events
  • RabbitMQ and Kafka basics
  • Rate limiting algorithms
  • Idempotency keys and API versioning
  • GraphQL vs REST and gRPC

Node.js MCQs with answers and explanations

Q1. How does a WebSocket connection start?

a) As an HTTP request with an Upgrade: websocket header, answered with 101 Switching Protocols

b) With a UDP handshake

c) By opening a raw TCP socket from the browser

d) With a DNS lookup that returns a socket ID

Q2. A developer points a plain browser WebSocket client at a Socket.IO server and it fails to connect. Why?

a) Browsers block WebSockets on Node.js

b) Socket.IO servers require a GraphQL schema

c) Socket.IO uses its own protocol on top of WebSocket and long polling, so it needs a Socket.IO client

d) Socket.IO only supports HTTP/1.0

Q3. You run a Socket.IO chat on three Node.js instances behind a load balancer. Users connected to different instances do not see each other's messages. What fixes this?

a) Increase the ping interval

b) Use an adapter such as the Redis adapter so events are broadcast across instances, plus sticky sessions if long polling is enabled

c) Store messages in localStorage

d) Switch to HTTP/2

Q4. Which statement about Server-Sent Events (SSE) is correct?

a) They allow the browser to send binary frames to the server

b) They require a WebSocket upgrade

c) They only work over UDP

d) The server streams text events to the browser over a normal HTTP response with Content-Type: text/event-stream

Q5. A dashboard only needs to receive live stock prices from the server and never sends data back on that channel. Which option is the simplest fit?

a) Server-Sent Events

b) A message queue in the browser

c) gRPC bidirectional streaming

d) Polling the database from the browser

Q6. Why would a Node.js API put a message queue between the order endpoint and the email service?

a) To decouple the services, so orders are accepted quickly and emails are processed and retried by workers even when the email service is slow or down

b) To make the HTTP response include the email body

c) To encrypt orders

d) Because Node.js cannot send emails

Q7. In RabbitMQ with manual acknowledgements, a consumer crashes after processing a message but before sending the ack. What happens?

a) The message is redelivered to a consumer, so it may be processed twice

b) RabbitMQ deletes the queue

c) The producer receives an error

d) The message is lost

Q8. What ordering guarantee does Kafka give?

a) Ordering by message size

b) Global ordering across all partitions of a topic

c) Ordering within a single partition only

d) No ordering at all

Q9. Which feature distinguishes Kafka from a traditional queue like RabbitMQ?

a) Kafka deletes each message as soon as one consumer reads it

b) Kafka cannot persist messages to disk

c) Kafka only supports one consumer

d) Kafka keeps messages in a log for a retention period, so consumers track offsets and can replay old messages

Q10. How does the token bucket rate-limiting algorithm behave?

a) Tokens are added at a fixed rate up to a maximum; each request uses a token, so short bursts up to the bucket size are allowed while the average rate stays limited

b) It delays every request by the same fixed time

c) It counts requests only per calendar day

d) It rejects every request after the first one

Q11. Your rate limiter stores counters in each Node.js process's memory, and the API runs on 4 instances. What is the problem?

a) Memory counters are always accurate

b) Each instance counts separately, so a client can make up to about 4 times the limit; use a shared store such as Redis

c) Rate limits cannot be applied to APIs

d) Express blocks shared memory

Q12. A mobile app retries POST /payments after a timeout. How do you prevent charging the customer twice?

a) Increase the timeout to 5 minutes

b) Send an Idempotency-Key header; the server stores the result for that key and returns the same response for retries instead of processing again

c) Switch the endpoint to GET

d) Ask the user to check their bank

Q13. Which change to a public REST API response normally needs a new API version?

a) Adding a new optional field

b) Removing a field or changing its type

c) Adding a new endpoint

d) Fixing a typo in documentation

Q14. Which problem does GraphQL mainly address compared with REST?

a) It removes the need for a server

b) It replaces authentication

c) It makes every query faster than SQL

d) The client asks for exactly the fields it needs in one request, avoiding over-fetching and multiple round trips

Q15. Which statement about gRPC is correct?

a) It uses Protocol Buffers over HTTP/2 with a .proto contract, and supports streaming; browsers need gRPC-Web or a proxy

b) It is a message queue

c) It only works between Python services

d) It uses JSON over HTTP/1.1 with no schema

Quick revision notes

  • WebSocket starts as an HTTP Upgrade, then sends frames both ways. Socket.IO needs its own client, and a Redis adapter to run on many servers.
  • SSE is one-way, server to client, over normal HTTP. It reconnects on its own using Last-Event-ID.
  • Queues deliver at least once, so make consumers safe to repeat. Kafka keeps order per partition and lets you replay.
  • Token bucket allows bursts. Keep rate-limit counters in a shared store and return 429 when the limit is hit.
  • Idempotency keys make retries safe. Removing a field needs a new API version. GraphQL fixes over-fetching. gRPC is protobuf over HTTP/2.

Frequently asked questions

Should I use WebSockets or SSE for notifications?

If only the server pushes updates, SSE is simpler and runs over plain HTTP. Use WebSockets when the client also sends messages often, like in chat or multiplayer games.

Should I use RabbitMQ or Kafka in a Node.js project?

RabbitMQ is a good fit for task queues and message routing, where each message is acked one by one. Kafka is better for large event streams that many consumers read and replay.

Is GraphQL better than REST?

Not always. GraphQL helps when clients need data in different shapes. REST is easier to cache with HTTP, and easier to secure and monitor because each endpoint is separate.

Comments

Answered 0/0Correct 0