Video in progress
The service you work on depends on 5 more services, PostgreSQL and Kafka. How do you make local development easier?
I don't run every service locally. I bring up the infrastructure (DB, Kafka) with Docker Compose or Testcontainers, and replace neighboring services with WireMock stubs or with their version in a shared dev environment.
📖 Answer
The first instinct is to put all 6 services in docker-compose.yml. A month later the laptop struggles on 16 GB, one of the services needs a new env variable and won't start, and half a day goes to "why isn't it working".
A setup that works better in practice:
- Infrastructure in containers. The Spring Boot 3.1+
spring-boot-docker-composemodule brings upcompose.yamlitself when the app starts, and provides connection settings automatically for supported images (PostgreSQL, Redis and others):
# compose.yaml
services:
postgres:
image: postgres:16
environment:
POSTGRES_PASSWORD: secret
kafka:
image: apache/kafka:3.8.0
-
Neighboring services as stubs. Instead of
customer-service, WireMock gives canned responses. This also forces you to depend on their contract, not on how they work. -
If you need real integration, connect to the service in a shared dev or staging environment (for example, by switching
customer.base-urlthrough a profile).
Another option is to use Testcontainers in dev mode: a TestApplication class in src/test brings up the app together with the containers using SpringApplication.from(Application::main).with(ContainersConfig.class). There's one configuration, for tests and for running locally.
The key is that the local environment comes up in ten minutes. If it isn't a single command in the README, a new person spends their first week on it.
Sign up to mark studied questions and save your progress.