How to model relationship using event sourcing?

313 views
Skip to first unread message

Leo Zhang

unread,
Jun 20, 2020, 5:34:40 PM6/20/20
to DDD/CQRS
In our scenario, we have a Course entity to represent course content. For each student attending a course, there is a CourseSession entity representing the learning progress of the student in the course. So there is a one-to-many relationship between Course and CourseSession. If using relational database, there will be a course table and course_session table, in which course has a unique ID and course session is uniquely identified by (courseId + studentId). We try to model this using event sourcing, and our event table is like following

------------------------------------------------------------------
| entity_type | entity_id | event_type | event_data |
------------------------------------------------------------------

this is fine for storing course, there is a courseId we can use as entity_id. But for CourseSession, there isn't an intrinsic id attribute, we have to use the concatenation of (courseId + studentId) as entity_id, which is not quite natural. Is there a better way to model this kind of relationship?

mynkow

unread,
Nov 18, 2020, 2:00:25 AM11/18/20
to DDD/CQRS
Actually what you have suggested is how I do it all the time and it is very natural.

Usually I use URNs for identifiers. => https://tools.ietf.org/html/rfc5141

Here is an example:

CourseId => urn:boundedcontext:course:123
CourseSessionId  => urn:boundedcontext:course:123/student:456

Nils Kilden-Pedersen

unread,
Dec 10, 2020, 9:54:03 AM12/10/20
to ddd...@googlegroups.com
Seems to me that CourseSession is just another entity (AR) which needs its own identifier, same as with Course and Student.

--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dddcqrs/7878d9ef-b792-4045-8212-4fb79dccb5a2o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages