What's the alternative for a web service/distributed system if it is not using a stub?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
In a distributed system or web service architecture, communication between different software components or services is critical. Traditionally, this is often facilitated through stubs in a model known as Remote Procedure Calls (RPC). However, there are several alternatives when a system chooses not to use a stub. These alternatives can broadly be categorized into direct API calls, message queues, and service meshes.
1. Direct API Communication
Direct API communication is a simple and straightforward method where services communicate with each other over HTTP or other protocols without an intermediary. This method often uses REST, GraphQL, or gRPC without generating client-side stub code.
REST (Representational State Transfer) - Uses standard HTTP methods like GET, POST, PUT, DELETE, etc., and can be easily consumed by a variety of clients including browsers and mobile devices. REST is stateless, meaning that each request from a client to server must contain all the information needed to understand the request.
GraphQL - Provides a more efficient and powerful alternative to REST. It allows clients to request exactly the data they need, reducing the bandwidth and improving performance. It also simplifies data aggregation from multiple sources with a single API call.
gRPC - A modern open source high performance RPC framework that can run in any environment. It uses HTTP/2 for transport, Protocol Buffers as the interface description language, and provides features like authentication, load balancing, blocking or non-blocking bindings, and streaming.
2. Message Queues
Message queues offer a different approach where communication happens via a message-passing system instead of direct API calls. This decouples the services by sending messages to a queue which can be read and processed by one or more components independently. Examples include Apache Kafka, RabbitMQ, and Amazon SQS.
Messaging systems are especially beneficial for:
- Handling peak loads by buffering incoming requests.
- Asynchronously processing messages.
- Ensuring delivery even if the consuming service is temporarily down.
3. Service Meshes
A service mesh is a dedicated infrastructure layer built into an application. This transparently handles service-to-service communications, management, and security. Popular implementations like Istio, Linkerd, and Consul provide robust features including:
- Service discovery
- Load balancing
- Encryption
- Monitoring and tracing
- Fault injection and recovery
Table: Comparison of Alternatives
| Feature | Direct API | Message Queue | Service Mesh |
| Communication Style | Synchronous | Asynchronous | Both |
| Complexity | Low | Medium | High |
| Performance | High | Depends on Usage | High |
| Scalability | Moderate | High | High |
| Fault Tolerance | Low | High | High |
Conclusion
Choosing an alternative to stubs in a distributed system or web service depends on the specific needs including scalability, fault tolerance, and the complexity of operations. Direct API calls might simplify development and reduce overhead but might not handle large scale or reliable communication as effectively as message queues or service meshes can.
In practice, complex systems might employ a combination of these strategies to leverage the unique benefits of each, thereby crafting a resilient, scalable, and efficient ecosystem.

