> For the complete documentation index, see [llms.txt](https://docs.gameket.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gameket.io/introduction/concepts/best-practices.md).

# Best Practices

#### 1. Always Use Idempotency Keys

```javascript
headers['Idempotency-Key'] = generateUUID();
```

#### 2. Implement Retry Logic

```javascript
async function retryRequest(fn, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      await sleep(Math.pow(2, i) * 1000); // Exponential backoff
    }
  }
}
```

#### 3. Handle Rate Limiting

```javascript
if (response.status === 429) {
  const retryAfter = response.headers.get('retry-after');
  await sleep(parseInt(retryAfter) * 1000);
  // Retry request
}
```

#### 4. Log Request IDs

```javascript
console.log(`Request ${requestId} completed in ${duration}ms`);
```

#### 5. Validate Query Parameters

```javascript
const validStatuses = ['pending', 'completed', 'refunded'];
if (!validStatuses.includes(status)) {
  throw new Error(`Invalid status: ${status}`);
}
```
