Pastebin (10 K) --> 12,5 K
Previous figures x 10
POST /v1/pastes
The body of the request is a JSON with the expiration and the content of the pastebin
{
"expiration_in_minutes" : 10,
"content" : ""
}
Returns the paste id:
HTTP/1.1 201 Created
Location: /v1/pastes/a1b2c3d4
GET /v1/pastes/{paste_id}
Returns the pastebin information (creation date, expiration date and content)
GET /v1/pastes?limit=nn&offset=nn
Returns list of pastebins for the loged user.
Optional URL parameters to define maximum number of results (limit) and offset (offset).
For performance reason 50 is a hard max limit, and default is 10.
Example response
{
"pagination": {
"total_items": 135,
"limit": 25,
"offset": 50
},
"data": [
{
"_id": "x7y8z9w0",
"created_at": "2025-07-15T12:00:00Z",
"expires_at": "2025-07-15T13:00:00Z"
}
]
}
DELETE /v1/pastes/{pastabin_id}
Deletes a pastebin if it belongs to the current loged user
Common response codes:
{
"_id": ObjectId("67890abcdef1234567890ab"), // Handled by MongoDB
"owner_id": "user-uuid-1234", // The owner's identifier
"created_at": ISODate("2025-07-15T12:00:00Z"),
"expires_at": ISODate("2025-07-15T13:00:00Z"), // Can be null if it never expires
"content": "Your multi-line content goes here."
}
Indexes
_id) is the default collection index. Fast, unique lookups for a single paste (GET /pastes/{id}). No action needed.{ owner_id: 1, created_at: -1 }. Compound index. Efficiently retrieve pastes for a specific user, sorted by creation date.{ expires_at: 1 } (with filter). For retrieving expired documents.Partition key
_id is used as the partition key for sharding, expecting an even distribution of data and load.
DNS
Translates domain names to IPs.
Load balancer
Distributes requests to Kubernetes cluster ingress controller. It can balance between different regions for disaster recovery.
API Gateway
Validates JWT token and redirects to IAM in case of logging needed (posting).
Manages rate limitting / throtling
Central request logging point.
Identity and Access Management
Implemented with Keycloack.
It can provide different flows for differente clients (browser, mobile app)
Ofloads user management and authentication.Dedicated specialized application that improves security and regulatory compliance.
Enables social login and identity federation with other IAM systems.
REST API
Run as Spring Boot microservices that writes and reads pastes to / from Pastebin database.
It also uses a cache to store and retrieve last used pastebins.
Expiration service
Periodically deletes expired pastes from database and Redis.
Implemented as a Spring Batch Kubernetes CronJob.
Pastes database
Storage for pastes information. Implemented with MongoDB.
Cache
Stores cached pastes for reducing latency and database load. Implemented with Redis for
Application layer, Monitoring and Alerting layer, and Logging & Analytics layer are run in a k8s cluster.
For high availability, several nodes are run in 2 availability zones.
For failover and disaster recovery, another cluster can be started to takeover in a different region.
Log Collector
Fluent bit service that collects application logs and forwards them to Logging and Analytics system.
Telemetry Collector
OpenTelemetry Collector that forwards traces to Logging and Analytics system.
Centralices logs and traces to help SRE / DevOps teams the analysis of issues and the system behaviour.
Data Prepper
Prepares logs content before inserting into OpenSearch.
Open Search
Indexes logs and traces to allow easy search and analysis.
It also sends alerts to Alertmanager when specific error logs are found.
Dashboards
Provide a productive user interface with dashboards to analyse and search for logs and traces.
Prometheus
Scrapes metrics from applications, and stores them in a TSDB.
Grafana
Provides dashboards for metrics visualization
Alertmanager
Handles alarms providint the following functionalities:
Some requests requiere authentication. It is enforced in API Gateway, that checks a valid JWT is present in the request, and the RES API implementation, that searches for the appropriate scope.
Data is encripte in transit and in rest.
Sequence diagrams are provided for request flows of the following APIs:
High availability and durability achieved with 5 nodes distributed across 3 different availability zones. 5 replicas distributed across the 3 availability zones (2-2-1)
Scalability achieved with partitioning.
When crating or updating a paste, strong consistenchy achieved writhing to 3 nodes.
For reading, eventual consistency is allowed. Reads of recent pastes are retrieved from the cache. If paste not chached t has been stored in secondary replicas or the cache is down, in which case a secondary replica is used to avoid overloading the primary. So secondaryPrefered + available read concern is selected.
High availability and scalability achieved with a Redis Cluster.
The cluster provides high availability and partitioning for scalability.
The cache is used in 2 scenarios:
For high availability a 5 nodes cluster spread across 3 availability zones in a region.
Database selection
The data requierements include:
Taking all of this into account, a NoSQL database is selected.
MongoDB is selected because it's widely known, provides flexibility for data schema, allows flexible consistency depending per requests depending on the operation and it has low operational overhead. A wide-column store as Cassandra is not requiered based on data volume and write throughput.
Cache updates
Sync writting to cache is performed instead of async processing using queues because:
If many queries are received in a short period of time the following measures can be applied:
In case of a high demand spike, Redis can become a bottleneck. In this situation new nodes for new partitions can be added. It can be performend:
In case to be able to recover in case of regional outage, a disaster recovery strategy could be used:
Include functionality for pastes visibility.
Async notifications to users informing of soon paste expiration. This could be implemented with SSE for web application and push notifications for movile devices.