task management
productivity
task completion
to-do list
efficiency

Mark task as completed

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Marking a task as completed looks simple in the user interface, but the underlying implementation should do more than flip a checkbox. A good design updates status consistently, records when completion happened, supports undo, and keeps the operation idempotent so repeated clicks do not corrupt data. This matters whether you are building a to-do app, a project tracker, or an internal workflow tool.

Model Completion as a State Change

At the data level, “completed” is usually one state in a task lifecycle. A minimal task model often includes:

  • a status field such as pending, in_progress, or completed
  • a completion timestamp
  • the user who completed the task, if auditing matters

A typical SQL update looks like this:

sql
1UPDATE tasks
2SET status = 'completed',
3    completed_at = CURRENT_TIMESTAMP
4WHERE id = 42
5  AND status <> 'completed';

The last condition makes the update idempotent. If the task is already completed, the statement does not keep changing data pointlessly.

Implement the API So It Is Safe to Repeat

A backend endpoint should be designed so that pressing the complete button twice does not create inconsistent side effects.

javascript
1app.patch('/tasks/:id/complete', async (req, res) => {
2  const taskId = Number(req.params.id);
3
4  const result = await db.query(
5    `UPDATE tasks
6     SET status = 'completed', completed_at = NOW()
7     WHERE id = $1 AND status <> 'completed'
8     RETURNING id, status, completed_at`,
9    [taskId]
10  );
11
12  if (result.rowCount === 0) {
13    return res.status(200).json({ message: 'Task already completed or not found' });
14  }
15
16  res.json(result.rows[0]);
17});

This example uses an idempotent PATCH route. The exact transport can vary, but the design principle should remain the same.

Update the UI Immediately, Then Reconcile

In interactive apps, optimistic UI usually gives the best experience. Mark the task complete in the interface right away, then confirm with the server response.

javascript
1function completeTask(taskId) {
2  setTasks(tasks =>
3    tasks.map(task =>
4      task.id === taskId ? { ...task, status: 'completed' } : task
5    )
6  );
7
8  return fetch(`/tasks/${taskId}/complete`, { method: 'PATCH' });
9}

If the request fails, roll the UI state back and show an error. That keeps the application fast without hiding backend truth.

Support Undo and Auditability

Many systems need more than a one-way status flip. If users can click the wrong item, an undo path is valuable.

A robust implementation often stores:

  • 'completed_at'
  • 'completed_by'
  • an activity log entry such as “Task marked completed by Priya at 14:05”

That makes the action understandable later, especially in shared team tools.

Consider Derived Workflows

Completion may trigger other rules. For example:

  • update project progress percentages
  • notify subscribers
  • archive the task from the default view
  • unlock the next step in a checklist

Keep those side effects separate from the raw status update when possible. The status change should remain simple and reliable, while downstream workflow logic can react to it.

Common Pitfalls

  • Treating completion as only a front-end checkbox without storing a real task state.
  • Making the endpoint non-idempotent so repeated clicks cause duplicate notifications or logs.
  • Overwriting completion metadata every time the same action is retried.
  • Hiding completed tasks immediately without giving users a way to undo mistakes.
  • Mixing unrelated business rules directly into the basic status update path.

Summary

  • Marking a task complete should be modeled as a deliberate state change.
  • Store status and completion metadata, not just a visual checkmark.
  • Make the backend operation idempotent.
  • Use optimistic UI carefully and reconcile with server truth.
  • Keep side effects such as notifications and progress updates separate from the core completion update.

Course illustration
Course illustration

All Rights Reserved.