Performance: Callbacks overview
MEDIUM IMPACT
Callbacks affect the server response time and database transaction speed by adding extra processing steps during model lifecycle events.
class User < ApplicationRecord after_commit :enqueue_heavy_job def enqueue_heavy_job HeavyJob.perform_later(self.id) end end
class User < ApplicationRecord before_save :heavy_computation def heavy_computation # complex calculations or external API calls end end
| Pattern | Server Processing | Database Impact | Response Delay | Verdict |
|---|---|---|---|---|
| Heavy logic in before_save | High CPU usage | Blocks transaction | Increases latency | [X] Bad |
| Lightweight after_commit with background job | Minimal CPU | Non-blocking | Fast response | [OK] Good |