Case study · Internal operations

Handling Requests by E-Mail

Support and security requests arrive by e-mail. ticketd turns them into tickets in queues that a team works on, with time booking and access for the people who asked. The system runs as a single file in my own operations, without a cloud service.

Starting point

Requests arrive by e-mail, and they end up in mailboxes. Nobody knows who is handling what, what has been answered and how much time it costs. Ready-made service desks solve that, but they usually require an account with a provider, and the requests leave the house.

I wanted a system that a small team understands, that runs without a cloud service and that I can explain in operation. The mailboxes may live at a provider, the processing stays local.

The system at a glance

ticketd is a single process with a local database and no mandatory infrastructure. It accepts mail, input in the browser and calls through the interface, and it holds all data itself.

ticketd, ein ProzessAntwortenMesswertePostfächerbeim Anbieter oder lokalTeamWeboberflächeAnfragendeLink und PINAndere ProgrammeJSON-Schnittstelle, ZugriffstokenEingangWeb, Schnittstelle, Mail-AbrufAnwendungsdiensteAufnahme, Bearbeitung,Versand, ZugangAnschlüsseDatenbank, SMTP, IMAP, DateienSQLitePostgreSQL optionalDateispeicherSMTP-AusgangPrometheus
One process, local data, everything external through narrow connectors. (Diagram labels in German.)

Three layers

Inside, ticketd is built in layers that each talk in one direction only.

Layer Parts Task Rule
Entry Web interface, JSON interface, mail retrieval Accept requests and check input Never touches the database directly
Application Services for intake, handling, sending, access and administration Run the flows and decide permissions Knows neither the web interface nor a database product
Connectors Database, SMTP, IMAP, file storage Hide technology behind narrow interfaces Translates technical errors into domain errors

The start-up program assembles the concrete parts. Everything else only knows the interfaces.

The path of a mail

A mail is not just stored, it is assigned to a case. For that, ticketd reads the mailboxes at regular intervals, splits each message and detects duplicates. If someone replies to an earlier mail, it lands in the same ticket again.

WarteschlangeticketdAbruf und AufnahmePostfachAntwortet die Person, ordnet ticketd die Mailwieder demselben Ticket zu.AnfragendeTeamMail senden1Postfach regelmäßig abrufen2Mail zerlegen, Duplikat erkennen,einem Ticket zuordnen3neues oder bestehendesTicket4Ticket bearbeiten, Zeitbuchen5Antwort schreiben6Antwort per SMTP7
A mail becomes a ticket, the reply becomes a mail again. (Diagram labels in German.)

Access for requesters

Whoever has made a request should be able to see its status and write to it without creating an account. Access works in two steps: a one-time link by mail, then a PIN.

janeinjaneinEinmaliger Linkper MailLink gültig?nicht verbraucht,nicht abgelaufenPIN richtig?Zugang verweigertLink verbrauchen und Sitzunganlegen, in einer TransaktionFehlversuch zählen,danach vorübergehend sperrenSignierte SitzungJede Anfrage: Sitzung prüfen,Ticket nur aus der Sitzung
Link, PIN, session: the decision is made on the server. (Diagram labels in German.)

The link is stored only as a checksum, the PIN as a hash with an additional secret. Which ticket someone sees follows exclusively from the session the server has verified, not from parameters of the request. Foreign attachments are treated as if they did not exist. The team’s access is separate from this.

Five decisions that shape the rest

The architecture decisions are recorded as short notes with context, decision and consequences. Five of them shape ticketd the most.

One process, local database

ticketd is a monolithic process with a local database and no mandatory infrastructure. SQLite is the default. The small variant knows only SQLite and rejects other databases explicitly instead of half-supporting them.

Rejected: An external database from the start. It increases the operating effort that SQLite reduces considerably.

Price: With many simultaneous writes, several instances or a wish for replication, SQLite is not enough. There is a second build profile with PostgreSQL for that.

Database changes as explicit files

The schema changes only through numbered SQL files that the program carries embedded. Which changes have run is recorded in the database. There is no silent adjustment at run time.

Rejected: Automatic migration at start-up, derived by the database layer from the models.

Price: Every change to the schema needs a migration file written for it.

Permissions per queue, default is deny

A team member sees only tickets of the queues they belong to, and nothing without a membership. The same rule applies to attachments.

Rejected: Make everything visible by default and maintain exceptions.

Price: A new team member sees nothing at first, until someone assigns them to a queue.

ADR 0008 Separate the layers step by step

The web interface and the interface were not supposed to talk to the database directly but to call application services. The rebuild went step by step, first ticket list and overview, then the remaining flows. The application stayed runnable throughout.

Rejected: Rebuild everything in one go. I wanted to avoid the risk of such a big bang.

Price: In the meantime old and new paths existed side by side.

ADR 0002 Breaks instead of legacy

In the move to the shared architecture the rule was: no backward compatibility. Old formats were removed, obsolete keys got no fallback, breaking changes are stated explicitly in the documentation. That saves complexity in the long run.

Rejected: Compatibility bridges: keep old formats running in parallel and support obsolete configuration keys with fallback behaviour.

Price: Existing local setups had to be migrated actively.

Operation

Operation is not an afterthought here, it is part of the design.

  • One file or one container. There is a small variant with SQLite and a full one with a PostgreSQL driver, each for several platforms.
  • Strict configuration. One JSON file, unknown fields are an error. Individual values can be overridden through environment variables with a uniform prefix. Contradictory settings, such as a certificate without a key or the same connection for web and metrics, are rejected by the program at start-up.
  • TLS as needed. With its own certificate or, for local operation, with a self-signed one created at start-up. Its fingerprint is logged so that it can be verified.
  • Observe without disturbing the application. Metrics for Prometheus come on a connection of their own, separate from the web interface and the interface. Calls, duration, errors and the state of mail retrieval are recorded. There are also checks for “alive” and “ready”.
  • Credentials stay out of the logs. Secret parts of addresses are masked in the request log.
  • Maintenance by command line. An administration program runs migrations, creates users and queues, inspects single tickets, imports mail from files and rebuilds the search index.
  • Checks. The tests run through with go test.

What I take from this for businesses

A service desk for a small team is not a large system, but the design questions are the same as for larger ones. The following table is a translation, not a client result.

Design principle Translation for your business
One process, local data Little operation, no dependency on a provider account
Entry, application and connectors separated The database or the mail server can be swapped without touching the flows
Permissions per queue, default is deny Only those responsible see requests
Decision on the server, not in the browser Requesters see only their own ticket
Changes as explicit files Every schema change is traceable and reviewable
Breaks instead of legacy A rebuild stays manageable if you do not hedge in every direction