Code Monkey home page Code Monkey logo

dlho-discount-code-generator's Introduction

Discount Code system

This application is a Discount Code System implemented using gRPC (Google Remote Procedure Call) in .NET. It allows generating and using discount codes through a server-side application.

  • app
  • test

Features

  • Discount Code Generation: The system can generate unique discount codes of length 7-8 characters.
  • Discount Code Usage: Clients can use generated discount codes.
  • Real-time Communication: Clients can communicate with the server in real-time using the gRPC protocol.
  • Persistence: Generated discount codes persist even if the server is restarted.
  • Scalability: The system is capable of processing multiple requests in parallel.

Requirements

  • .NET Core SDK
  • Docker or a locally running PostgreSQL installation
  • Code Editor (Visual Studio is recommended)

Technologies Used

  • .NET and gRPC: A high-performing and open-source version of RPC framework
  • Entity Framework Core: ORM for interacting with the database.
  • xUnit and Moq: Testing frameworks for unit testing.
  • .NET Console Application: Client side implementation.
  • PostgresSQL: Relational database management system for storing discount codes
  • Docker: For containerizing our database

Getting started

  • Unzip the project:
  • Navigate to the project directory
  • If you don't have a local PostgreSQL installation, start one in docker: docker-compose up -d using the docker compose file provided
  • Adjust the .env and appsettings.json with your PostgreSQL credentials (they already match the ones from the docker command above).
    • Update the database with migrations: dotnet ef database update
  • Start the app (both backend and frontend at once): <Multiple Startup Projects> in visual studio
  • Or follow the steps below to run the app
    • Navigate to the server-side project directory: cd dlho-solutions/DiscountCodeGenerator/Server/DLHO.DiscountCodeGenerator.gRPC
    • Run the server applications: dotnet run
    • Navigate to the client-side project directory: cd dlho-solutions/DiscountCodeGenerator/Client/DLHO.DiscountCodeGenerator.App
    • Run the client applications: dotnet run

Usage

Run the client-side application and follow the instructions.

Generating Discount Codes

To generate discount codes, clients can call the GenerateCodesAsync method exposed by the gRPC service. Clients need to specify the number of codes they want to generate.

Using Discount Codes

Clients can use discount codes by calling the UseCodeAsync method exposed by the gRPC service. Clients need to provide the discount code they want to use.

Fetch Discount Codes

Clients can use view generated codes by calling the GetCodesAsync method exposed by the gRPC service.

App Implementation and Consideration

To complete this task, I used the gRPC protocol because of the following reasons:

  • Performance: gRPC is a high-performance Remote Procedure Call (RPC) framework designed for low latency and efficient data transfer. This is ideal for the this scenario where we need to handle multiple requests in parallel for discount code generation and usage.
  • Strong Typing: gRPC uses Protocol Buffers which define the data format for requests and responses. This ensures type safety and reduces the chance of errors during communication between server and client compared to raw TCP sockets. This aligns perfectly with the defined request and response formats in the document.
  • Scalability: gRPC is designed for scalable microservices architecture. Since it's mentioned in the requirement that the server can be restarted without affecting generated codes, gRPC allows for easier integration with potential future scaling needs.
  • TCP Sockets: While TCP offers low-level control and reliable communication, It require significant manual effort to manage data serialization and deserialization, making it less suitable for this structured communication.
  • WebSockets: WebSockets are good for real-time bi-directional communication, but might be overkill for this system where communication is request-response based.

dlho-discount-code-generator's People

Contributors

bloggrammer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.