Point-to-Point vs Publish-Subscribe Interview Questions and Answers
Learn the differences between Point-to-Point (Queue) and Publish-Subscribe (Topic) messaging with JMS, Spring Boot, IBM MQ, ActiveMQ, architecture diagrams, and real-world interview examples.
Point-to-Point vs Publish-Subscribe Interview Questions and Answers
One of the most frequently asked messaging interview questions is:
What is the difference between Point-to-Point and Publish-Subscribe messaging?
These are the two fundamental messaging models supported by JMS, IBM MQ, ActiveMQ, and many other messaging systems.
Choosing the correct messaging model depends entirely on your business requirements.
JMS Messaging Models
flowchart LR
JMS --> Point-to-Point
JMS --> Publish-Subscribe
Q1. What is Point-to-Point (P2P) Messaging?
Answer
Point-to-Point messaging uses a Queue.
A producer sends a message to a queue, and only one consumer receives and processes that message.
Once processed successfully, the message is removed from the queue.
Architecture
flowchart LR
Producer --> Queue
Queue --> Consumer
Characteristics
- One Producer
- One Queue
- One Consumer processes each message
- Message removed after successful processing
Common Use Cases
- Payment Processing
- Order Processing
- Billing
- Loan Processing
- Batch Jobs
Q2. What is Publish-Subscribe Messaging?
Answer
Publish-Subscribe uses a Topic.
A publisher sends a message to a topic, and every subscribed consumer receives a copy of the message.
Architecture
flowchart LR
Publisher --> Topic
Topic --> SubscriberA["Subscriber A"]
Topic --> SubscriberB["Subscriber B"]
Topic --> SubscriberC["Subscriber C"]
Characteristics
- One Publisher
- Multiple Subscribers
- Every subscriber receives the event
- Supports event broadcasting
Common Use Cases
- Notifications
- Monitoring
- Analytics
- Audit Logging
- Stock Price Updates
Q3. What is the main difference between Queue and Topic?
Answer
| Queue | Topic |
|---|---|
| Point-to-Point | Publish-Subscribe |
| One Consumer | Multiple Consumers |
| Task Processing | Event Broadcasting |
| Load Distribution | Event Distribution |
| Message Removed After Consumption | Every Subscriber Receives Event |
Visual Comparison
flowchart LR
Producer --> Queue
Queue --> Consumer
flowchart LR
Publisher --> Topic
Topic --> ConsumerA["Consumer A"]
Topic --> ConsumerB["Consumer B"]
Topic --> ConsumerC["Consumer C"]
Q4. When should we use a Queue?
Answer
Use a Queue when:
- Only one service should process the request.
- Duplicate processing is not allowed.
- Tasks must be distributed among workers.
Examples
- Payment Service
- Invoice Generation
- Inventory Update
- Background Jobs
- Payroll Processing
Banking Example
ATM Withdrawal
↓
Withdrawal Queue
↓
Core Banking
Only one Core Banking service should debit the account.
Q5. When should we use a Topic?
Answer
Use a Topic when multiple applications must react to the same business event.
Example
Customer places an order.
The following services need the event:
- Inventory
- Notification
- Loyalty
- Analytics
- Audit
Architecture
flowchart LR
OrderService["Order Service"] --> Topic
Topic --> Inventory
Topic --> Notification
Topic --> Analytics
Topic --> Audit
Q6. Can multiple consumers read from a Queue?
Answer
Yes.
Multiple consumers can listen to the same queue.
However, each individual message is delivered to only one consumer.
Queue Load Balancing
flowchart LR
Queue --> Consumer1["Consumer 1"]
Queue --> Consumer2["Consumer 2"]
Queue --> Consumer3["Consumer 3"]
RabbitMQ and IBM MQ distribute messages among available consumers.
Q7. Can multiple subscribers receive the same Topic message?
Answer
Yes.
Every subscriber receives its own copy of the published message.
Topic Broadcast
flowchart LR
Publisher --> Topic
Topic --> Billing
Topic --> Inventory
Topic --> Shipping
Topic --> Analytics
This makes Topics ideal for Event-Driven Architecture.
Q8. How does Spring Boot work with Queue and Topic?
Answer
Spring Boot supports both models using Spring JMS.
Queue Example
REST API
↓
JmsTemplate
↓
Queue
↓
@JmsListener
Topic Example
REST API
↓
JmsTemplate
↓
Topic
↓
Subscriber A
↓
Subscriber B
↓
Subscriber C
Spring Boot Architecture
flowchart TD
RestApi["REST API"] --> SpringBoot["Spring Boot"]
SpringBoot["Spring Boot"] --> JmsTemplate
JmsTemplate --> Queue
JmsTemplate --> Topic
Q9. What are the advantages and disadvantages of each model?
Point-to-Point
Advantages
- Load Balancing
- Reliable Task Processing
- Simple Architecture
- Better Resource Utilization
Disadvantages
- Only one consumer processes a message.
- Not suitable for broadcasting events.
Publish-Subscribe
Advantages
- Loose Coupling
- Multiple Consumers
- Easy Event Distribution
- Scalable
Disadvantages
- Duplicate event processing must be handled independently.
- More monitoring is required.
Q10. Which model is used in modern Microservices?
Answer
Modern systems often use both models.
Queues are used for:
- Payment Processing
- Order Fulfillment
- Background Tasks
Topics are used for:
- Domain Events
- Notifications
- Analytics
- Audit
- Event Streaming
Enterprise Architecture
flowchart TD
OrderService["Order Service"] --> OrderQueue["Order Queue"]
OrderService["Order Service"] --> OrderTopic["Order Topic"]
OrderQueue["Order Queue"] --> PaymentService["Payment Service"]
OrderTopic["Order Topic"] --> Notification
OrderTopic["Order Topic"] --> Analytics
OrderTopic["Order Topic"] --> Audit
Queue vs Topic Comparison
| Feature | Queue | Topic |
|---|---|---|
| Messaging Model | Point-to-Point | Publish-Subscribe |
| Consumers | One per Message | Multiple |
| Delivery | Single Consumer | All Subscribers |
| Load Balancing | Yes | No |
| Event Broadcasting | No | Yes |
| Best For | Task Processing | Event Distribution |
Queue Processing Lifecycle
sequenceDiagram
participant Producer
participant Queue
participant Consumer
Producer->>Queue: Send Message
Queue->>Consumer: Deliver Message
Consumer-->>Queue: ACK
Queue-->>Queue: Remove Message
Topic Processing Lifecycle
sequenceDiagram
participant Publisher
participant Topic
participant Subscriber1
participant Subscriber2
participant Subscriber3
Publisher->>Topic: Publish Event
Topic->>Subscriber1: Event
Topic->>Subscriber2: Event
Topic->>Subscriber3: Event
Real Banking Example
A customer transfers ₹1,00,000.
Queue
Transfer Request
↓
Transfer Queue
↓
Core Banking
Only one Core Banking service processes the transaction.
Topic
Transfer Completed Event
↓
Transfer Topic
↓
Notification
↓
Fraud Detection
↓
Analytics
↓
Audit
Multiple downstream systems react independently to the completed transfer.
Production Best Practices
Queue
- Enable transactions.
- Configure retries.
- Configure Dead Letter Queues.
- Use Manual Acknowledgments.
- Monitor queue depth.
Topic
- Design idempotent subscribers.
- Version event schemas.
- Monitor subscriber lag.
- Handle duplicate events.
- Secure broker communication.
Senior Interview Tips
Interviewers frequently ask:
- Queue vs Topic?
- Point-to-Point vs Publish-Subscribe?
- When should you choose Queue?
- When should you choose Topic?
- Can multiple consumers read from a Queue?
- Can multiple subscribers receive the same Topic event?
- How does Spring Boot support both?
- Which messaging model is used in Event-Driven Architecture?
- Which model is used for payment processing?
- Which model scales better?
Remember:
- Queue = Work Distribution
- Topic = Event Distribution
- Queue = One Consumer
- Topic = Many Subscribers
Quick Revision
- JMS supports two messaging models: Point-to-Point and Publish-Subscribe.
- Point-to-Point uses Queues where each message is processed by one consumer.
- Publish-Subscribe uses Topics where every subscriber receives the event.
- Queues are ideal for task processing and load balancing.
- Topics are ideal for event broadcasting and Event-Driven Architecture.
- Spring Boot supports both models using Spring JMS.
- Use Queues for payments, billing, and order processing.
- Use Topics for notifications, analytics, audit, and microservices events.
- Design consumers to be idempotent in Topic-based systems.
- Understanding Queue vs Topic is one of the most common enterprise messaging interview questions.