TLDR: Modeling Udemy's Categories in a Relational Database
Date: 2021-04-19 Source: https://arpitbhayani.me/blogs/taxonomy-on-sql
Overview
Model Udemy's taxonomy on a relational database. Learn efficient SQL queries, indexing, and design for optimal performance. In this essay, we will model taxonomy on top of a relational database, and as a specific example, we will try to build Udemy’s Taxonomy.
Key Points
- all the 3 tables will have an identical schema
- if we were to introduce a new level, say concept
- what if for a few topics we want it to be a child of a category, leaving out sub-categories altogether; handling this with this design will be very tricky.
- Get topic by ID: The most common query that we’d need is getting a topic by its id and this is very well facilitated by making id as a primary key of the table.
- Get the topic path: Getting a topic path is an interesting use case.
- Getting all the children of a category or a sub-category will be heavily used to drive the “Browse and Explore” page, where users would want to drill down and explore the kind of topics Udemy covers.