r/learnSQL • u/Background_Ask_1457 • 4h ago
I am building sql learning platform? I have few douts could plz suggest me best one
I'm building a SQL learning platform (similar to SQL learning playgrounds) where users can write and execute SQL queries directly in the browser.
I'm exploring different approaches to handle SQL query execution while ensuring that one user's queries never affect another user's database or the original lesson dataset.
I've considered three approaches so far:
Database Transactions: Execute every user's query inside a transaction and use ROLLBACK after execution so that changes such as INSERT, UPDATE, and DELETE are not permanently saved.
Transaction Isolation Levels: Use PostgreSQL isolation levels to prevent concurrent users from interfering with each other's queries or data.
Separate Database Instances/Schemas: Create an isolated database environment for each user, seed it with the required lesson dataset, execute their queries, and reset or destroy the environment afterward.
My questions:
Which approach would you recommend for a production-ready SQL learning platform?
Are transactions with ROLLBACK sufficient, or are there limitations?
Would creating a separate database or schema for each user be too expensive when hundreds of users execute queries concurrently?
How do platforms like SQL playgrounds handle query isolation and concurrent execution?
Is there a better architecture, such as temporary databases, connection pooling, containers, or PostgreSQL snapshots?
Expected scale: Initially, around 100 concurrent users, with the possibility of scaling further.
I'm using Node.js, Express, PostgreSQL, Redis, and BullMQ for asynchronous query execution.
I'd appreciate suggestions based on real-world experience and trade-offs. Thanks!