Apache Dubbo is a high-performance Java RPC framework for microservices. Popular in Chinese enterprise ecosystems, it provides service registration, discovery, load balancing, and governance.

Architecture

  Consumer → Registry (Nacos/Zookeeper) → Provider
    ↕                                        ↕
    └────── Direct RPC call ─────────────────┘
  
Component Role
Provider Exposes service implementation
Consumer Calls remote service
Registry Service discovery (Nacos, Zookeeper)
Monitor Tracks call statistics

Setup

  <dependency>
    <groupId>org.apache.dubbo</groupId>
    <artifactId>dubbo-spring-boot-starter</artifactId>
    <version>3.2.10</version>
</dependency>
<dependency>
    <groupId>com.alibaba.nacos</groupId>
    <artifactId>nacos-client</artifactId>
    <version>2.3.0</version>
</dependency>
  

Provider

  dubbo:
  application:
    name: order-service
  protocol:
    name: dubbo
    port: 20880
  registry:
    address: nacos://localhost:8848
  
  @DubboService
public class OrderServiceImpl implements OrderService {
    @Override
    public OrderDto getOrder(Long id) {
        return orderRepository.findById(id)
            .map(this::toDto)
            .orElseThrow(() -> new OrderNotFoundException(id));
    }
}
  

Consumer

  @RestController
public class OrderController {
    @DubboReference
    private OrderService orderService;

    @GetMapping("/orders/{id}")
    public OrderDto getOrder(@PathVariable Long id) {
        return orderService.getOrder(id);
    }
}
  

Service Interface

Shared API module (deployed as JAR to both provider and consumer):

  public interface OrderService {
    OrderDto getOrder(Long id);
    List<OrderDto> getOrdersByUser(Long userId);
    OrderDto createOrder(CreateOrderRequest request);
}
  

Load Balancing

Strategy Description
random Random selection (default)
roundrobin Round-robin
leastactive Fewest active calls
consistenthash Hash by parameter (same param → same provider)
  @DubboReference(loadbalance = "leastactive", timeout = 3000, retries = 2)
private OrderService orderService;
  

Cluster Fault Tolerance

Strategy Behavior
failover Retry other providers (default)
failfast Fail immediately
failsafe Ignore errors, return null
failback Retry failed calls in background
forking Parallel call multiple providers

Dubbo vs Spring Cloud OpenFeign

Feature Dubbo OpenFeign
Protocol Custom (dubbo://) HTTP/REST
Performance Higher (binary) Lower (JSON/HTTP)
Service mesh Built-in Via Spring Cloud
Ecosystem Alibaba/Chinese Global/Spring
Browser access No Yes (REST)

Best Practices

  • Define service interfaces in a shared API module
  • Set appropriate timeouts and retry policies
  • Use Nacos for both registry and configuration
  • Monitor call metrics via Dubbo Admin dashboard
  • Prefer REST/gRPC for new polyglot microservices; Dubbo for Java-only RPC