Advertisement
tacheshun

coding challange

Jul 13th, 2025 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 14.03 KB | Source Code | 0 0
  1. # Code Challenge: Audit Log API
  2.  
  3. ## Objective
  4.  
  5. Develop a comprehensive audit logging API system that tracks and manages user actions across different applications. This system should be designed to handle high-volume logging, provide search and filtering capabilities, and ensure data integrity and security.
  6.  
  7. ## Requirements:
  8.  
  9. ### Core Features:
  10.  
  11. #### Audit Log Management:
  12. - **Log Entry Creation**: API endpoints to create audit log entries with metadata
  13. - **Structured Data**: Each log entry should include:
  14.  - User ID and session information
  15.   - Action performed (CREATE, UPDATE, DELETE, VIEW, etc.)
  16.   - Resource type and ID (e.g., "user", "order", "product")
  17.   - Timestamp with timezone
  18.   - IP address and user agent
  19.   - Before/after state changes (for modifications)
  20.   - Custom metadata fields
  21.   - Severity level (INFO, WARNING, ERROR, CRITICAL)
  22.   - **Tenant ID**: Multi-tenant support for multiple applications/organizations
  23.  
  24. #### Search and Retrieval:
  25. - **Advanced Search**: Filter logs by date range, user, action type, resource type, severity, **tenant ID**
  26. - **Full-text Search**: Search through log messages and metadata
  27. - **Pagination**: Handle large result sets efficiently
  28. - **Export Functionality**: Export logs in JSON, CSV formats
  29. - **Real-time Log Streaming**: WebSocket endpoint for real-time log monitoring
  30. - **Tenant Isolation**: Ensure complete data isolation between tenants
  31.  
  32. #### Data Management:
  33. - **Data Retention**: Configurable retention policies (e.g., keep logs for 90 days)
  34. - **Data Archival**: Move old logs to cold storage
  35. - **Data Compression**: Efficient storage for large log volumes
  36. - **Backup and Recovery**: Automated backup procedures
  37.  
  38. ### Technical Requirements:
  39.  
  40. #### API Design:
  41. - **API Gateway**: Choose between AWS API Gateway or Application Load Balancer based on requirements
  42. - **RESTful API** following OpenAPI 3.0 specification
  43. - **Authentication**: JWT-based authentication
  44. - **Authorization**: Role-based access (Admin, Auditor, User) with **tenant-based access control**
  45. - **Rate Limiting**: Prevent API abuse
  46. - **Request Validation**: Input sanitization and validation
  47. - **Error Handling**: Proper HTTP status codes and error messages
  48. - **Search Integration**: OpenSearch for advanced search capabilities
  49. - **Multi-tenancy**: Support for multiple tenants with complete data isolation
  50.  
  51. #### Database Design:
  52. - **Database Choice**: Select one of the three options based on your preference and requirements:
  53.   - **PostgreSQL + TimescaleDB**: Optimized for time-series data with efficient partitioning
  54.   - **MongoDB**: Document-based storage with flexible schema for audit logs
  55.   - **DynamoDB**: Serverless NoSQL with automatic scaling and built-in encryption
  56. - **Multi-tenant Schema**: Design schema to support multiple tenants with proper isolation
  57. - **Optimized Schema**: Design for high-volume writes and complex queries based on your chosen database
  58. - **Indexing Strategy**: Efficient indexes for search operations (database-specific) including tenant-based indexes
  59. - **Data Partitioning**: Consider time-based and tenant-based partitioning for large datasets
  60. - **Connection Pooling**: Handle concurrent requests efficiently
  61.  
  62. #### Performance:
  63. - **High Throughput**: Handle 1000+ log entries per second
  64. - **Low Latency**: Sub-100ms response times for search queries
  65. - **Message Queue**: AWS SQS for background task processing and data archival
  66. - **Async Processing**: Background tasks for data archival and cleanup using SQS
  67.  
  68. #### Security:
  69. - **Data Encryption**: Encrypt sensitive log data at rest
  70. - **Access Control**: Fine-grained permissions for log access with tenant isolation
  71. - **Audit Trail**: Log access to the audit logs themselves
  72. - **Data Masking**: Mask sensitive information in logs (PII, passwords)
  73. - **Tenant Isolation**: Complete data isolation between tenants at all levels
  74. - **Cross-tenant Protection**: Prevent data leakage between tenants
  75.  
  76. ### Implementation Details:
  77.  
  78. #### Technology Stack:
  79. - **Framework**: Django or FastAPI
  80. - **API Gateway**: Choose one of:
  81.  - **AWS API Gateway** (for serverless, managed API management)
  82.   - **Application Load Balancer (ALB)** (for traditional load balancing)
  83. - **Database**: Choose one of:
  84.  - **PostgreSQL** with TimescaleDB extension (for time-series data)
  85.   - **MongoDB** (for document-based storage)
  86.   - **DynamoDB** (for serverless, scalable NoSQL)
  87. - **Message Queue**: AWS SQS for background task processing
  88. - **Search**: OpenSearch (optional, for advanced search capabilities)
  89.  
  90. #### API Endpoints:
  91. ```
  92. POST   /api/v1/logs                    # Create log entry (with tenant ID)
  93. GET    /api/v1/logs                    # Search/filter logs (tenant-scoped)
  94. GET    /api/v1/logs/{id}              # Get specific log entry (tenant-scoped)
  95. GET    /api/v1/logs/export            # Export logs (tenant-scoped)
  96. GET    /api/v1/logs/stats             # Get log statistics (tenant-scoped)
  97. POST   /api/v1/logs/bulk              # Bulk log creation (with tenant ID)
  98. DELETE /api/v1/logs/cleanup           # Cleanup old logs (tenant-scoped)
  99. WS     /api/v1/logs/stream            # Real-time log streaming (tenant-scoped)
  100. GET    /api/v1/tenants                # List accessible tenants (admin only)
  101. POST   /api/v1/tenants                # Create new tenant (admin only)
  102. ```
  103.  
  104. #### System Architecture:
  105. ```mermaid
  106. graph TB
  107.     subgraph "Client Applications"
  108.         App1[Application 1<br/>Tenant A]
  109.         App2[Application 2<br/>Tenant B]
  110.         App3[Application 3<br/>Tenant C]
  111.     end
  112.    
  113.     subgraph "API Gateway Layer"
  114.         APIGateway[AWS API Gateway]
  115.         ALB[Application Load Balancer]
  116.     end
  117.    
  118.     subgraph "Audit Log API"
  119.         Auth[Authentication]
  120.         TenantAuth[Tenant Authorization]
  121.         RateLimit[Rate Limiting]
  122.     end
  123.    
  124.     subgraph "Core Services"
  125.         LogService[Log Service<br/>Multi-tenant]
  126.         SearchService[Search Service<br/>Tenant-scoped]
  127.         ExportService[Export Service<br/>Tenant-scoped]
  128.         StreamService[Stream Service<br/>Tenant-scoped]
  129.     end
  130.    
  131.     subgraph "Data Layer"
  132.         PostgreSQL[(PostgreSQL + TimescaleDB<br/>Tenant-partitioned)]
  133.         MongoDB[(MongoDB<br/>Tenant-collections)]
  134.         DynamoDB[(DynamoDB<br/>Tenant-partitioned)]
  135.         OpenSearch[(OpenSearch<br/>Tenant-indices)]
  136.     end
  137.    
  138.     subgraph "Message Queue"
  139.         SQS[AWS SQS<br/>Tenant-queues]
  140.     end
  141.    
  142.     subgraph "Background Services"
  143.         Workers[SQS Workers<br/>Tenant-aware]
  144.         Cleanup[Data Cleanup<br/>Tenant-scoped]
  145.         Archive[Data Archival<br/>Tenant-scoped]
  146.     end
  147.    
  148.     App1 --> APIGateway
  149.     App1 --> ALB
  150.     App2 --> APIGateway
  151.     App2 --> ALB
  152.     App3 --> APIGateway
  153.     App3 --> ALB
  154.    
  155.     APIGateway --> Auth
  156.     ALB --> Auth
  157.     Auth --> TenantAuth
  158.     TenantAuth --> RateLimit
  159.     RateLimit --> LogService
  160.     RateLimit --> SearchService
  161.     RateLimit --> ExportService
  162.     RateLimit --> StreamService
  163.    
  164.     LogService --> PostgreSQL
  165.     LogService --> MongoDB
  166.     LogService --> DynamoDB
  167.     SearchService --> OpenSearch
  168.     ExportService --> PostgreSQL
  169.     ExportService --> MongoDB
  170.     ExportService --> DynamoDB
  171.    
  172.     LogService --> SQS
  173.     Workers --> SQS
  174.     Cleanup --> SQS
  175.     Archive --> SQS
  176. ```
  177.  
  178. #### Audit Log Flow:
  179. ```mermaid
  180. sequenceDiagram
  181.     participant Client as Client App<br/>(Tenant A)
  182.     participant Gateway as API Gateway/ALB
  183.     participant Auth as Auth Service
  184.     participant TenantAuth as Tenant Auth
  185.     participant Log as Log Service
  186.     participant DB as Database (Tenant A)
  187.     participant SQS as AWS SQS
  188.     participant Search as OpenSearch
  189.     participant Worker as SQS Worker
  190.    
  191.     Client->>Gateway: POST /api/v1/logs<br/>(tenant_id: A)
  192.     Gateway->>Auth: Validate JWT Token
  193.     Auth-->>Gateway: Token Valid
  194.     Gateway->>TenantAuth: Validate Tenant Access
  195.     TenantAuth-->>Gateway: Tenant Access Granted
  196.     Gateway->>Log: Create Log Entry (Tenant A)
  197.     Log->>DB: Store Log Entry (Tenant A)
  198.     Log->>SQS: Queue Background Tasks (Tenant A)
  199.     Log-->>Gateway: Log Created
  200.     Gateway-->>Client: 201 Created
  201.    
  202.     Note over SQS,Worker: Background Processing (Tenant A)
  203.     SQS->>Worker: Process Background Tasks
  204.     Worker->>Search: Index for Search (Tenant A)
  205.     Worker->>DB: Data Cleanup/Archival (Tenant A)
  206.    
  207.     Note over Client,Search: Real-time Streaming (Tenant A)
  208.     Client->>Gateway: WS /api/v1/logs/stream<br/>(tenant_id: A)
  209.     Gateway->>Log: Subscribe to Stream (Tenant A)
  210.     Log->>Client: Real-time Log Updates (Tenant A)
  211. ```
  212.  
  213. ### Testing:
  214.  
  215. - **Unit Tests**: >85% code coverage
  216. - **Integration Tests**: API endpoint testing
  217. - **Performance Tests**: Load testing with realistic data volumes
  218. - **Security Tests**: Authentication and authorization testing
  219.  
  220. ### Documentation:
  221.  
  222. - **API Documentation**: OpenAPI/Swagger documentation
  223. - **Setup Instructions**: Clear deployment and configuration guide
  224. - **Architecture Diagram**: System design and data flow
  225. - **Code Documentation**: Inline comments and docstrings
  226.  
  227. ### Bonus Features (Optional):
  228.  
  229. - **Alert System**: Configure alerts for specific log patterns
  230. - **Dashboard**: Simple web interface for log visualization
  231. - **Log Analytics**: Basic analytics and reporting
  232. - **Log Correlation**: Group related log entries by request ID
  233.  
  234. ### Submission:
  235.  
  236. - **Git Repository**: Clean, well-structured code
  237. - **README**: Comprehensive setup and usage instructions
  238. - **API Documentation**: Complete endpoint documentation
  239. - **Postman Collection**: Test the API endpoints
  240. - **Architecture Diagram**: System design overview
  241. - **Live Demo**: Deployed application (optional)
  242.  
  243. ### Evaluation Criteria:
  244.  
  245. #### Code Quality & Architecture (30%):
  246. - **Code Structure**: Clean, maintainable, and well-structured code
  247. - **API Design**: RESTful principles, proper error handling, validation
  248. - **Database Design**: Efficient schema design and query optimization with multi-tenant support
  249. - **Multi-tenancy**: Proper implementation of tenant isolation and access control
  250. - **Technical Decisions**: Justification of technology choices and architecture
  251.  
  252. #### Performance & Scalability (25%):
  253. - **High Throughput**: Ability to handle 1000+ log entries per second
  254. - **Low Latency**: Sub-100ms response times for search queries
  255. - **Message Queue**: Effective use of AWS SQS for background processing
  256. - **Database Optimization**: Efficient design and query performance for chosen database
  257.  
  258. #### Security & Compliance (20%):
  259. - **Authentication**: Proper JWT-based authentication implementation
  260. - **Authorization**: Role-based access control and fine-grained permissions with tenant isolation
  261. - **Data Protection**: Encryption at rest and in transit
  262. - **Input Validation**: Proper sanitization and validation of all inputs
  263. - **Tenant Isolation**: Complete data isolation between tenants
  264.  
  265. #### Testing & Documentation (15%):
  266. - **Test Coverage**: >85% code coverage with comprehensive testing
  267. - **API Documentation**: Complete OpenAPI/Swagger documentation
  268. - **Setup Instructions**: Clear deployment and configuration guide
  269. - **Code Documentation**: Inline comments and comprehensive docstrings
  270.  
  271. #### Problem Solving & Innovation (10%):
  272. - **Complex Requirements**: Ability to handle complex requirements efficiently
  273. - **Creative Solutions**: Innovative approaches to technical challenges
  274. - **Database Choice**: Justification and implementation of chosen database technology
  275. - **API Gateway Choice**: Selection and implementation of API Gateway or ALB
  276. - **SQS Integration**: Effective use of AWS SQS for background processing
  277. - **OpenSearch Integration**: Implementation of advanced search capabilities
  278. - **Multi-tenancy**: Effective implementation of tenant isolation and access control
  279. - **Bonus Features**: Implementation of optional advanced features
  280. - **Performance Optimization**: Creative solutions for performance challenges
  281.  
  282. ## Timeline:
  283.  
  284. This challenge is designed to be completed in **3-5 business days**:
  285. #### **Days 1-2: Core API Development**
  286. - Set up project structure and technology stack
  287. - Choose and configure database (PostgreSQL/MongoDB/DynamoDB)
  288. - Set up API Gateway or ALB
  289. - Implement core audit log management features
  290. - Design and implement database schema
  291. - Create basic API endpoints
  292. - Set up AWS SQS for background processing
  293. - Configure OpenSearch for search capabilities
  294.  
  295. #### **Days 3-4: Advanced Features & Testing**
  296. - Implement search, filtering, and export functionality
  297. - Add real-time streaming capabilities
  298. - Implement security and authentication
  299. - Create comprehensive test suite
  300.  
  301. #### **Day 5: Documentation & Final Review**
  302. - Complete API documentation
  303. - Create architecture diagrams
  304. - Final testing and optimization
  305. - Prepare submission materials
  306.  
  307. Focus on delivering a working MVP with core features rather than implementing all bonus features.
  308.  
  309. ## Priority Focus Areas:
  310.  
  311. #### **Must Complete (High Priority):**
  312. - Core audit log creation and retrieval API endpoints
  313. - Database setup and configuration (PostgreSQL/MongoDB/DynamoDB)
  314. - API Gateway or ALB setup and configuration
  315. - Basic search and filtering functionality
  316. - Database schema design and implementation with multi-tenant support
  317. - Authentication and authorization system with tenant isolation
  318. - Basic security controls and data validation
  319. - AWS SQS setup for background processing
  320. - OpenSearch setup for search capabilities
  321. - Multi-tenant implementation and tenant management
  322.  
  323. #### **Should Complete (Medium Priority):**
  324. - Advanced search with full-text capabilities using OpenSearch
  325. - Real-time log streaming via WebSocket
  326. - Data retention and archival policies using SQS
  327. - Performance optimization and database-specific tuning
  328. - Comprehensive test coverage
  329. - SQS worker implementation for background tasks
  330. - API Gateway/ALB advanced features (rate limiting, caching)
  331.  
  332. #### **Nice to Have (Low Priority):**
  333. - Export functionality (JSON, CSV)
  334. - Dashboard and visualization interface
  335. - Advanced analytics and reporting
  336. - Alert system for log patterns
  337.  
  338. ## Questions?
  339.  
  340. Any questions you may have, please contact us by e-mail.
  341.  
  342. Good luck! 🚀
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement