Cloud Native 26 min read

How to Choose the Right Cloud‑Native Microservice Framework (MicroProfile vs Spring)

This article explains why cloud‑native microservices are beneficial, defines their key characteristics, compares the MicroProfile and Spring frameworks, and provides detailed code examples for REST APIs, configuration, fault tolerance, security, health checks, metrics, and distributed tracing to help developers select the most suitable technology stack.

JakartaEE China Community
JakartaEE China Community
JakartaEE China Community
How to Choose the Right Cloud‑Native Microservice Framework (MicroProfile vs Spring)

Cloud‑Native Microservice Characteristics

Externalized configuration – change configuration without rebuilding.

Statelessness – state stored in external databases; any instance can be replaced.

Fault tolerance – services remain functional when downstream services fail.

Discoverability – services expose capabilities for client consumption.

Security – each service has its own identity and enforces authentication/authorization.

Observability – metrics, health checks, and tracing are exposed for monitoring.

Traceability – correlation IDs are propagated so tools such as Zipkin or Jaeger can reconstruct call chains.

Framework comparison: MicroProfile vs Spring

Both frameworks provide the building blocks for cloud‑native microservices. MicroProfile is a community‑driven set of specifications (12‑factor, Jakarta EE) supported by runtimes such as Open Liberty, Quarkus, Helidon, etc. Spring offers a mature ecosystem with Spring Boot, Spring MVC, Spring Cloud, and Spring Security.

REST API example (JAX‑RS)

@ApplicationPath("/rest")
public class CatalogApplication extends Application {}

@Path("/items")
@Produces(MediaType.APPLICATION_JSON)
public class CatalogService {
    @GET
    public List<Item> getInventory() { /* ... */ }

    @GET
    @Path("{id}")
    public Response getById(@PathParam("id") long id) { /* ... */ }
}

Endpoint:

http://{host}:{port}/rest/items

REST API example (Spring MVC)

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

@RestController
@RequestMapping("/items")
public class CatalogController {
    @GetMapping
    public List<Item> getInventory() { /* ... */ }

    @GetMapping("/{id}")
    public ResponseEntity<Item> getById(@PathVariable long id) { /* ... */ }
}

Dependency injection

MicroProfile uses CDI with @Inject. Spring uses its own container with @Autowired or @Inject.

Externalized configuration

MicroProfile Config reads values from microprofile-config.properties, environment variables, or system properties and injects them with @ConfigProperty:

Config config = ConfigProvider.getConfig();
String url = config.getValue("elasticsearch_url", String.class);
// or
@Inject @ConfigProperty(name="elasticsearch_url") String url;

Spring achieves the same with a bean annotated @ConfigurationProperties or with @Value("${elasticsearch.url}") on fields.

Fault tolerance

MicroProfile provides annotations to build resilient services:

@Timeout(value = 2, unit = ChronoUnit.SECONDS)
@Retry(maxRetries = 2, maxDuration = 2000)
@CircuitBreaker
@Fallback(fallbackMethod = "fallbackInventory")
public List<Item> getInventory() { /* ... */ }

Spring typically uses Netflix Hystrix or Resilience4j with @HystrixCommand (or Resilience4j equivalents) to achieve similar behavior.

Security

MicroProfile integrates MicroProfile JWT with Java EE security annotations such as @RolesAllowed and @DeclareRoles. Spring secures endpoints with Spring Security, often via @EnableWebSecurity, @PreAuthorize, or method‑level role checks.

Health checks

MicroProfile Health exposes /health/ready and /health/live endpoints using @Readiness and @Liveness annotations on beans that implement HealthCheck. Spring Boot Actuator provides /actuator/health, aggregating beans that implement HealthIndicator.

Metrics

Both frameworks expose a /metrics endpoint. MicroProfile uses annotations such as @Timed, @Counted, and @Metered to create custom metrics. Spring Actuator publishes metrics via Micrometer and allows custom MeterBinder implementations.

Distributed tracing

MicroProfile OpenTracing propagates trace IDs automatically for JAX‑RS calls and can be applied to custom methods with @Traced. Spring Cloud Sleuth automatically adds trace IDs to logs and supports Zipkin or Jaeger as back‑ends.

REST client

MicroProfile Rest Client is type‑safe. Example registration:

@Dependent
@RegisterRestClient(baseUri="http://localhost:9080/system")
public interface InventoryServiceClient {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    List<Item> getAllItems();
}

Inject the client with @Inject @RestClient. Spring uses Feign with

@FeignClient(name="inventory-service", url="${inventoryService.url}")

and enables it via @EnableFeignClients.

JSON handling

MicroProfile 2.x supports JSON‑B and JSON‑P. Example serialization with JSON‑B:

import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;

Car car = new Car("VW", "TGUAN", "HN19MDZ");
Jsonb jsonb = JsonbBuilder.create();
String json = jsonb.toJson(car);
Car restored = jsonb.fromJson(json, Car.class);

Spring can use Jackson ObjectMapper or JSON‑B in the same way.

Managing many services

When operating hundreds of microservices, externalized configuration (e.g., Kubernetes ConfigMaps), health probes, and metrics collection are essential. Kubernetes probes can call /health/live and /health/ready (MicroProfile) or /actuator/health (Spring) to determine pod readiness.

Getting started

MicroProfile starter: https://start.microprofile.io/ – choose a runtime such as Open Liberty, Quarkus, Helidon, etc. Spring Initializr: https://start.spring.io/ – generates a Spring Boot project with the selected dependencies.

cloud-nativemicroservicesobservabilityKubernetesSpringMicroProfile
JakartaEE China Community
Written by

JakartaEE China Community

JakartaEE China Community, official website: jakarta.ee/zh/community/china; gitee.com/jakarta-ee-china; space.bilibili.com/518946941; reply "Join group" to get QR code

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.