Spring Boot service for managing courses in an EdTech platform. The application models courses, course materials, and enrollments and exposes REST endpoints for course lookup, lifecycle management, and user enrollment.
The service acts as a course catalog and enrollment backend for an EdTech system. Administrators can create and update courses, learners can view course details, and the platform can enroll users into courses while coordinating with user and payment services.
- List all courses
- Retrieve courses by id, name, or instructor
- Inspect course materials for a course
- Create, update, and delete courses
- Enroll a user in a course with a persisted lifecycle state machine
- Make enrollment idempotent so duplicate requests reuse the existing enrollment
- Verify users through a user-service Feign client before enrollment
- Create a payment record through a payment-service Feign client after enrollment
- Publish enrollment, payment, and notification events for downstream workflows
- Provide a Hystrix fallback for enrollment failures
- Persist course, material, and enrollment data with JPA
- Return simple success/error messages for course operations
GET /coursesGET /courses/{id}GET /courses/name/?name=...GET /courses/courseMaterial/?id=...GET /courses/instructor/?instructor=...POST /coursesPUT /courses/{id}DELETE /courses/{id}POST /courses/course/{courseId}/register/{userId}
The v9 snapshot keeps the Feign-based integration but adds explicit enrollment states, idempotent duplicate handling, broker-side lifecycle events, and Spring-backed integration tests so the workflow is easier to trace and reason about.
- The API receives a course id and user id.
- The service first checks whether an enrollment already exists for the same user and course.
- If a record already exists, the service returns the existing enrollment state and does not create a second payment or enrollment row.
- If no record exists, the service creates an
Enrollmentrecord inINITIATEDstate. - The service calls the user-service client to verify the user exists and advances the record to
USER_VERIFIED. - The enrollment moves to
PAYMENT_PENDINGbefore the payment-service call. - If payment succeeds, the record is updated to
ENROLLED. - If user verification or payment fails, the record is persisted as
FAILEDbefore the exception bubbles up to the Hystrix fallback.
flowchart LR
Initiated[INITIATED] --> Verified[USER_VERIFIED]
Verified --> Pending[PAYMENT_PENDING]
Pending --> Enrolled[ENROLLED]
Initiated --> Failed[FAILED]
Verified --> Failed
Pending --> Failed
Enrolled --> Enrolled
Failed --> Failed
The v8 snapshot adds RabbitMQ-backed event publishing without changing the synchronous enrollment contract. The service now emits JSON messages for lifecycle transitions, payment requests, and duplicate-request notifications.
ENROLLMENT_INITIATEDUSER_VERIFIEDPAYMENT_REQUESTEDCONFIRMEDFAILEDDUPLICATE_REQUEST
sequenceDiagram
participant Client
participant CourseAPI as Course Service
participant UserSvc as user-service
participant PaySvc as payment-service
participant RabbitMQ
Client->>CourseAPI: POST /courses/course/{courseId}/register/{userId}
CourseAPI->>CourseAPI: Check enrollment idempotency key
alt Existing enrollment found
CourseAPI->>RabbitMQ: Publish duplicate-request notification
CourseAPI-->>Client: Return existing state message
else New enrollment
CourseAPI->>RabbitMQ: Publish enrollment initiated
CourseAPI->>UserSvc: Verify user
alt User not found
CourseAPI->>RabbitMQ: Publish failed + notification events
CourseAPI-->>Client: Return failure response
else User verified
CourseAPI->>RabbitMQ: Publish user verified
CourseAPI->>RabbitMQ: Publish payment requested
CourseAPI->>PaySvc: Create payment
alt Payment succeeds
CourseAPI->>RabbitMQ: Publish enrollment confirmed
CourseAPI-->>Client: Return success response
else Payment fails
CourseAPI->>RabbitMQ: Publish failed + notification events
CourseAPI-->>Client: Return failure response
end
end
end
- Exchange:
course.lifecycle.exchange - Routing keys:
course.enrollment.*,course.payment.*,course.notification.* - Payloads are serialized as JSON so future consumers can bind without changing the service contract
- Event payloads include the enrollment id, course id, user id, correlation key, lifecycle status, message, and timestamp
- Messaging is best-effort and does not block the enrollment workflow if the broker is unavailable
user-serviceviaEdTech.Course.feign.UserServicepayment-serviceviaEdTech.Course.feign.PaymentService- RabbitMQ via
EdTech.Course.service.CourseEventPublisher RestTemplatebean remains available for compatibility with the existing configuration
Courserepresents the core catalog itemCourseMaterialstores content tied to a courseEnrollmentlinks users to coursesEnrollmentStatusstores lifecycle states for the enrollment workflowuserId + course_idis treated as the idempotency key for enrollment requestsCourseDtois used for create and update requestsResponseMessagestandardizes simple API responsesPaymentis used when forwarding enrollment charges to the payment serviceCourseEventpackages broker-ready lifecycle metadata for downstream consumers
- Main application port:
8081 - Datasource:
edtech_course_service - Hibernate is configured for
updatemode - The service uses Spring Boot 2.7.13
- The app registers a load-balanced
RestTemplatebean for service-to-service calls - Enrollment requests are idempotent for the same user and course
- Enrollment records are persisted at each lifecycle stage so failures remain traceable
- Hystrix fallback support is enabled for enrollment requests
- RabbitMQ host configuration is provided for local event publishing
- Java 17
- Spring Boot 2.7.13
- Spring Data JPA
- Spring JDBC
- Spring Web
- Spring Cloud LoadBalancer
- Spring Cloud OpenFeign
- Hystrix
- RabbitMQ
- MySQL
- Lombok
- Unit tests cover the enrollment state machine, duplicate handling, and broker payload publishing.
- Spring-based integration-style tests cover HTTP routing and service wiring with mocked collaborators.
java, spring-boot, spring-cloud, microservices, event-driven-architecture, rabbitmq, idempotency, hystrix, feign, jpa, mysql, rest-api, integration-tests
- The repository is intended to be extended with additional enrollment and payment workflows.
- The current service layer includes Feign-based user and payment integration.
- Generated build output is intentionally not tracked in git.