Useful Things For a Django Site¶
Reusable Apps¶
Events¶
Structured events > unstructured logging.
Structlog is good for this but it does get a little fiddly if you also want to pipe regular logs through it.
There is pretty messy overlap between structured logging and metrics. A single unified approach to both could probably be achieved with a little more thought than I have so far put into it.
The idea also intersects with publishing event streams for other to act on.
Jobs¶
Running standard management commands via a web based interface as background tasks.
Using introspection to build standard forms for available inputs, capturing outputs for future references etc.
The majority of this can be entirely independent of the actual task queue used. Small adapters could put together for the dispatch side of things that's task queue specific. You could even have a inline task queue option that just runs it in process.
Communications¶
Django has built in email sending support. It would be nice to have a drop in app that manages transactional (not marketing) communications a little more uniformly. Standard message classes that can produce both text and HTML flavoured email content. Dealing with sending, re-sending in the advent of temporary failure and marking addresses as defunct when failures are more permanent. Reports, alerting or some kind of actions being triggered when messages marked as mandatory fail.
Scheduling the sending out of band - so as not to tie up a request cycle.
It would be interesting to extend it to support SMS and possibly even push notifications, holding on to customer preferences for communication with smart fallbacks.
CQRS and Event Sourcing¶
CQRS is an interesting pattern where there is intentional separation of the read side of an application from the write side. It couples neatly with Event Sourcing where the audit log effectively is the source of truth for the system state. You can rebuild the read side at any point in time from the audit log alone. Log based application architecture is an interesting rabbit hole all by itself.
I suspect that it would be possible to write a neat little set of tools for using CQRS and Event Sourcing in Django applications without having to throw out everything that makes Django great.
Regular models for event storage, aggregates that deal with events and building state from them and then projector/projections for providing data for the read models. You could still use regular generic class based views for the read side at the least.
Like the job framework it shouldn't be too hard to make things like building projections from the events background tasks with small adaptors for different queues.