Nitin Agrawal
Contact -
  • Home
  • Interviews
    • InterviewFacts >
      • Secret Receipe
    • Resume Thoughts
    • Daily Coding Problems
    • BigShyft
    • Companies
    • Interviews Theory
    • Interview Questions
  • Programming Languages
    • Java Script >
      • Tutorials
      • Code Snippets
    • Reactive Programming >
      • Code Snippets
    • R
    • DataStructures >
      • LeetCode Problems >
        • Problem10
        • Problem300
      • AnagramsSet
    • Core Java >
      • Codility
      • Program Arguments OR VM arguments & Environment variables
      • Java Releases >
        • Java8 >
          • Performance
          • NasHorn
          • WordCount
          • Thoughts
        • Java9 >
          • ServiceLoaders
          • Lambdas
          • List Of Objects
          • Code Snippets
        • Java14 >
          • Teeing
          • Pattern
          • Semaphores
        • Java17 >
          • Switches
          • FunctionalStreams
          • Predicate
          • Consumer_Supplier
          • Collectors in Java
        • Java21 >
          • Un-named Class
          • Virtual Threads
          • Structured Concurrency
      • Threading >
        • ThreadsOrder
        • ProducerConsumer
        • Finalizer
        • RaceCondition
        • Executors
        • ThreadPoolExecutor
        • RecursiveTask
        • Future Or CompletableFuture
      • Important Points
      • Immutability
      • Dictionary
      • Sample Code Part 1 >
        • PatternLength
        • Serialization >
          • Kryo2
          • JAXB/XSD
          • XStream
        • MongoDB
        • Strings >
          • Reverse the String
          • Reverse the String in n/2 complexity
          • StringEditor
          • Reversing String
          • String Puzzle
          • Knuth Morris Pratt
          • Unique characters
          • Top N most occurring characters
          • Longest Common Subsequence
          • Longest Common Substring
        • New methods in Collections
        • MethodReferences
        • Complex Objects Comparator >
          • Performance
        • NIO >
          • NIO 2nd Sample
        • Date Converter
        • Minimum cost path
        • Find File
      • URL Validator
    • Julia
    • Python >
      • Decorators
      • String Formatting
      • Generators_Threads
      • JustLikeThat
    • Go >
      • Tutorial
      • CodeSnippet
      • Go Routine_Channel
      • Suggestions
    • Methodologies & Design Patterns >
      • Design Principles
      • Design Patterns >
        • TemplatePattern
        • Adapter Design Pattern
        • Proxy
        • Lazy Initialization
        • CombinatorPattern
        • Singleton >
          • Singletons
        • Strategy
  • Frameworks
    • Apache Velocity
    • React Library >
      • Tutorial
    • Spring >
      • Spring Boot >
        • CustomProperties
        • ExceptionHandling
        • Custom Beans
        • Issues
      • Quick View
    • Rest WebServices >
      • Interviews
      • Swagger
    • Cloudera BigData >
      • Ques_Ans
      • Hive
      • Apache Spark >
        • ApacheSpark Installation
        • SparkCode
        • Sample1
        • DataFrames
        • RDDs
        • SparkStreaming
        • SparkFiles
    • Integration >
      • Apache Camel
    • Testing Frameworks >
      • JUnit >
        • JUnit Runners
      • EasyMock
      • Mockito >
        • Page 2
      • TestNG
    • Blockchain >
      • Ethereum Smart Contract
      • Blockchain Java Example
    • Microservices >
      • Messaging Formats
      • Design Patterns
    • AWS >
      • Honeycode
    • Dockers >
      • GitBash
      • Issues
      • Kubernetes
  • Databases
    • MySql
    • Oracle >
      • Interview1
      • SQL Queries
    • Elastic Search
  • Random issues
    • TOAD issue
    • Architect's suggestions
    • Dynamic loading of agents
  • Your Views

Real-time transaction statistics calculation

5/13/2026

0 Comments

 
Problem Statement

Build a RESTful API for real-time transaction statistics calculation.
The service must maintain statistics for transactions that occurred
within the last 60 seconds and provide these statistics efficiently.

Requirements

    API Endpoints

    1. POST /transactions: Create a new transaction.

          Request Body:
          {
            "amount": "12.34",
            "timestamp": "2025-12-26T12:30:45.123Z"
          }

Field Specifications:
   - amount - Transaction amount as a string with decimal precision
   - timestamp - Transaction timestamp in ISO 8601 format

     2. GET /statistics: Return statistics based on transactions that occurred within the last 60
    seconds.


            Response Body:
                 {
                    "sum": "1500.50",
                    "avg": "150.05",
                    "max": "500.00",
                    "min": "10.50",
                    "count": 10
                }

   Response Code:
      - 200 OK - Successfully returned statistics

All monetary values must be returned as strings with exactly 2 decimal
places.

    3. DELETE /transactions: Delete all transactions.
        Response Code:
                - 204 No Content - All transactions successfully deleted

Performance Requirements (Optimal)

- POST /transactions must execute in O(1) time complexity
- GET /statistics must execute in O(1) time complexity (constant time)
- DELETE /transactions must execute in O(1) time complexity
- The API must handle high concurrency with thread-safe operations

  Technology Stack
          - Java 8+

  Deliverables

1. Fully functional REST API with all three endpoints
2. Thread-safe implementation supporting high concurrency
3. Unit tests covering core business logic
4. Integration tests validating API contracts and edge cases
5. Proper exception handling with correct HTTP status codes
6. Clean, maintainable code following SOLID principles

 Please share your thoughts.

0 Comments



Leave a Reply.

    Author

    Some Internet source or AI

    Archives

    May 2026

    Categories

    All

    RSS Feed

Powered by Create your own unique website with customizable templates.