performance

ruby
Rails.application.config.middleware.insert_before(
  Rack::Runtime,
  Rack::Timeout,
  service_timeout: 15  # 15 seconds
)

Request timeout handling with Rack::Timeout

rails reliability performance
by Alex Kumar 2 tabs
go
package feed

import (
	"encoding/base64"
	"encoding/json"
	"time"

Cursor-Based Keyset Pagination for a Postgres Feed API in Go

go postgres pagination
by codesnips 3 tabs
ruby
class LeaderboardCache
  TOP_KEY = "leaderboard:top".freeze
  STATS_KEY = "leaderboard:stats".freeze

  def top_players
    Rails.cache.fetch(TOP_KEY, expires_in: 5.minutes, race_condition_ttl: 15.seconds) do

Cache Stampede Protection with race_condition_ttl

rails caching performance
by codesnips 3 tabs
python
from django.db import models
from django.contrib.postgres.indexes import GinIndex


class Post(models.Model):
    title = models.CharField(max_length=200, db_index=True)

Django database index strategies

django python database
by Priya Sharma 1 tab
ruby
module MyApp
  class Application < Rails::Application
    config.load_defaults 6.1

    # Enable response compression
    config.middleware.use Rack::Deflater

API response compression with Rack::Deflater

rails performance api
by Alex Kumar 1 tab
go
package store

import (
  "context"
  "database/sql"
)

db/sql prepared statements with context and explicit Close

go sql postgres
by Leah Thompson 1 tab
ruby
class TrendingPostsService
  CACHE_KEY = 'trending_posts:v1'.freeze
  CACHE_TTL = 15.minutes

  def self.call(limit: 10)
    Rails.cache.fetch(CACHE_KEY, expires_in: CACHE_TTL) do

Redis caching for expensive computations

rails redis caching
by Alex Kumar 1 tab
java
package com.example.demo.config;

import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;

Caching strategies with Spring Cache

java spring-boot caching
by David Kumar 2 tabs
ruby
class LastSeenTracker
  THROTTLE = 5.minutes
  PENDING_KEY = "pending:last_seen".freeze

  class << self
    def touch(user_id, at: Time.current)

Database “Last Seen” without Hot Row Updates

rails performance redis
by codesnips 3 tabs
rust
use std::fs::File;
use std::io::{BufRead, BufReader, Result};

fn main() -> Result<()> {
    let file = File::open("input.txt")?;
    let reader = BufReader::new(file);

BufReader and BufWriter for efficient I/O buffering

rust io performance
by Marcus Chen 1 tab
python
from django.db import models
from django.contrib.postgres.indexes import GinIndex, BTreeIndex


class Order(models.Model):
    customer = models.ForeignKey('Customer', on_delete=models.CASCADE)

Django database indexes for query performance

django python database
by Priya Sharma 1 tab
php
<?php

use Illuminate\Support\Facades\Cache;

// Remember pattern - fetch from cache or execute closure
$posts = Cache::remember('posts.all', 3600, function () {

Laravel cache strategies for performance

laravel cache performance
by Carlos Mendez 4 tabs