Search code examples
pythondjangoframeworksprogramming-languages

Using Python w/ django - can I record a users input (keyboard and mouse) and play it back?


I'm not new to development (ran a number of business' built on .net, php, and even node.js), but I'm new to creating my own application from scratch. I've been researching on which language I should go with and I'm leaning towards Python with django and either postgreSQL or mongoDB as the DB. I'm comfortable modifying existing code, but I'm going to jump in and try building something from scratch.

I'd like to build a very simple online code editor where a user can input some code within their browser (color coded and formatted just like a traditional IDE). However, I'd like two things to happen:

1.) As they're entering code someone else (the viewer) can see the code entered as it's typed live.

2.) As a user is inputing code into the web code editor, their keystrokes and clicks are being recorded so that they can later be played back.

The idea would be that someone could write a snippet of code, and someone could later play back that snippet of code (almost like a video) to see how the coder arrived at that solution. It's sort of like a screen recording, except instead of recording the screen (which wouldn't be possible without an application installed on the end-users system), I'll record their inputs as they happen so that those inputs can be replayed.

Is that possible using python/django? Is there something already available in django (or something else) that would give me this recording/playback functionality?

Would postgreSQL be able to keep up with all those reads/writes if say 100 users were doing this at the same time? This may be a task better suited for something like mongoDB, but I'd prefer not to use a noSQL database as the DB for the entire site.

If you feel there's a better framework for this (like Rails) I'd be interested in hearing about that as well.


Solution

  • It is possible with Django(or any web framework for that matter). Although it seems a bit tough for a first project.

    The tough part will be performance/scallabiity. Since you want real time communication(one viewer sees live what the other one enters), you will probably need to incorporate websockets into your stack. Otherwise you won't be able to handle the load.

    The "replaying" part is easier. This will happen on the front-end side(Javascript), where you will store the keystrokes in small batches that you will periodically send to the server for persistence.

    You shouldn't worry about PostgreSQL keeping up with the load. See this presentation https://speakerdeck.com/zeeg/building-to-scale that explains that your DB is rarely the bottleneck. Also MongoDB is much slower than what is advertised. Most of the times it doesn't hold a candle in front of Postgres.

    Another interesting document is this benchmark(pdf)

    As for an existing django project that does what you want, I don't think there is one.