🔗 Demo
A high-performance country search application comparing Redis and Cloudflare KV performance, built with Next.js, providing real-time search suggestions with response time comparisons.
- Real-time country search with prefix matching
- Performance comparison between Redis and Cloudflare KV
- Sub-300ms response times
- Dark/Light theme support using Shadcn/ui
- Type-safe implementation
- Edge computing with Cloudflare Workers
- Redis and KV-powered search indexes
- Frontend: Next.js, TypeScript, Tailwind CSS, Shadcn/ui
- Backend: Cloudflare Workers, Hono
- Database: Redis (Upstash), Cloudflare KV
- Deployment: Vercel (Frontend), Cloudflare (API)
The application is built with four main components:
- Next.js Frontend: Handles user interface and parallel search interactions
- Redis Database: Stores and indexes country data using sorted sets
- Cloudflare KV: Provides alternative storage and search capabilities
- Cloudflare Workers API: Processes search requests at the edge
- Node.js 18+
- Yarn or npm
- Upstash Redis account
- Cloudflare account with Workers and KV access
- Clone the repository
- Install dependencies
- Set up environment variables:
cp .env.example .env.local- Update the following variables in your
.env.local:
REDIS_URL=your_redis_url
REDIS_TOKEN=your_redis_token
CLOUDFLARE_ACCOUNT_ID=your_account_id
CLOUDFLARE_API_TOKEN=your_api_token
CLOUDFLARE_NAMESPACE_ID=your_kv_namespace_id
├── src/
│ ├── app/
│ │ ├── api/
│ │ │ └── [[...route]]/
│ │ │ └── route.ts # API endpoints for Redis and KV
│ │ ├── components/
│ │ │ └── ui/ # Shadcn components
│ │ ├── layout.tsx # Root layout with theme
│ │ └── page.tsx # Main comparison page
│ ├── lib/
│ │ ├── seed.ts # Redis seeding script
│ │ └── seed-cloudflare.ts # KV seeding script
│ └── styles/
│ └── globals.css # Global styles and theme
The application performs parallel searches against both Redis and Cloudflare KV:
const search = async (searchTerm: string) => {
if (!searchTerm.trim()) {
setResult(null);
setKvResult(null);
return;
}
// Parallel search execution
Promise.all([
searchRedis(searchTerm),
searchKV(searchTerm)
]).catch(err => {
console.error('Search error:', err);
});
};The UI displays real-time performance metrics for both storage solutions:
- Response time comparison
- Result count comparison
- Search accuracy comparison
The application uses Tailwind CSS with Shadcn/ui components for a consistent design system:
- Dark/Light theme support
- Custom color variables
- Responsive design
- Accessible components
- Parallel Execution: Simultaneous Redis and KV queries
- Edge Computing: Low-latency responses
- Efficient Data Structures:
- Redis: Sorted sets for prefix matching
- KV: Key-based prefix search
- Type Safety: Full TypeScript implementation
- Client-side State Management: Optimized rendering
yarn build
vercel deployyarn deploy- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE.md file for details.
Project Link: https://github.com/yourusername/fast-country-search
This README provides a comprehensive overview of the project, including setup instructions, architecture details, and deployment guidelines. Remember to replace placeholder values (like usernames and social media links) with your actual information before using it.