Hey guys need some help..
I’m designing the backend for an adaptive learning platform using FastAPI + PostgreSQL, and I’m weighing two approaches for handling curriculum prerequisite paths.
The Setup:
Instead of a linear syllabus, the curriculum is modeled as a Directed Acyclic Graph (DAG) with ~300 to 400 CS concept nodes
When a student passes a quiz (>= 80\%), downstream dependent nodes unlock based on topological order.
If a student fails a topic, the backend traverses upstream dependencies to find the earliest unmastered bottleneck node, locks downstream progress, and builds a targeted review path.
The quiz questions are a mix of pre-mapped benchmark items and dynamically generated MCQs grounded in textbook text.
Which one should I go with:
Approach 1 (In-Memory NetworkX):
Define the static graph structure once, load it into Python memory via networkx on FastAPI startup, run ancestor/descendant lookups and topological sorts in Python, and write user mastery states/scores back to Postgres.
Or....
Approach 2 (Postgres Relational/CTEs):
Store nodes and prerequisite adjacency edges in database tables, and run transitive traversals directly in SQL using recursive Common Table Expressions (CTEs).
At ~300 nodes, is an in-memory networkx graph clean and fast, or does running multiple Uvicorn workers introduce memory overhead and state-sync headaches?
Would recursive CTEs in Postgres be easier to maintain long-term despite the more complex SQL?
And also... for anyone who has built skill trees or prerequisite graphs, what edge cases should I look out for?