instruction
stringlengths
34
36.1k
Say we have a company that provides services and they would like to build a new API to sell to clients who will use it for their websites. Some things to consider: The company has an old API that the company was able to sell to clients, however, the API was not designed very well and it is outdated and so it is hard t...
I have a web api with controller methods that use rest http(post/get calls). Clients consume this API with normal httpclient calls and I pass an http response back. My use case is I have a legacy method that needs to make a call to another server. This method currently uses WCF and contract binding but I don't want to ...
I have a subfunction, which is referenced in a number of my use cases. It looks something like this: User has the system fetch a list of all requests. User can filter and sort the list (filtering/sorting details below). User chooses a request and has the system fetch the full details of the request. I wish to detail ...
I'm reading a book which says: The third number, 719, indicates the build of the assembly. If your company builds its assembly every day, you should increment the build number each day as well. so it means to increment build number when you recompile the source code e.g. when you modify the source code.Then of cours...
We have a table design in our database to dynamically store settings: You wouldn't need to understand every column in the table but basically tbl_Setting defines all possible settings and tbl_SettingValue assigns a setting with a concrete value to an entity (user, project etc.). SETVL_T_Value contains a serialized va...
I am working in Angular project which is connected to REST API. Here we have an endpoint to create and update room types. POST endpoint for create and PUT endpoint for update exiting room types. Both POST & PUT API endpoints were developed to take one room type at a time as the payload. But frontend angular applicatio...
(I orignally posted my question on StackOverflow and figured maybe this would be a better place to ask) I provide details on the librairies I'm working with because it helps understand my issue but it could be applied to other projects as this is a general question on how to do a migration while still be able to use pr...
My question is about the way to represent data models created at runtime. To illustrate, let's say we would like to create a CMS-like app in which end-users may create custom forms. Those forms are themselves made of different field types (text, number, date...) A form model could be represented this way (language agno...
I'm working as the web developer with some friends who aren't coders themselves, but understand what goes on in the process. So, if it's been a week where I'm tackling a certain issue that I'm really confused by, I try to stay productive while attempting to piece together the new concepts by refactoring existing code, ...
I'm trying to solve a common problem of logging each method that calls 3rd party operation and I don't understand how to scale it up. Current implementation: public class ElasticsearchClient { RestHighLevelClient client = new RestHighLevelClient( RestClient.builder( new HttpHost("localh...
I need some clarification on White-Box vs Black-Box testing. Is it correct that: White-box testing is testing your code that you are familiar with? Black-box testing is testing someone else's code you are unfamiliar with, or having someone unfamiliar with your source code test it?
The Question: I'm developing an app in C# and am currently designing a menu which contains submenus and needs to be different depending on the category of the user. I've written the code but am struggling to structure it so that it is testable. I've read a lot about unit testing and testable code but still find it toug...
Suppose I have a Attendance class public class Attendance { private PersonInfo personInfo; public PersonInfo getPersonInfo() { return personInfo; } } And I want to check if person is registered in the Conference class: public class Conference { public boolean isRegistered(Attendance attendance) { ...
Is the dependency inversion principle an instance of orthogonalization? Given the class dependency X -> Y a common solution is to introduce interface Z so that the dependencies become X -> Z <- Y. In the first case a change in Y might cause a change in X. After introduction of Z a change in X will not cause Y to change...
What is the best way to model the objects in my OOP program? I understand that the classes represent not particular objects but "groups"/"generalizations" of objects. But, I need to model individual objects that are significant in my domain for example Garfield and Snoopy below, which aren't a class of object at all bu...
I've developed a backend project using Python. It collects data from different sources, process the data, and then perform actions with it (for example, store relevant info in a database). To execute it, I just do python main.py and it starts the daemon process. Now I want to add a Flask API in order to interact with t...
I've built a React Web application with an Express REST API server and Firebase Auth. Also, Nginx is set up as a reverse proxy, so API calls from React to https://mydomain.com/api are routed to backend http://localhost:8002. Now I want to publish part of my APIs under https://api.mydomain.com with an API Key scheme. I...
I have a web service with the methods GetUser and AddUser, and some DTOs (Data Transfer Objects) GetUser: retrieves user information, as a DTO called UserGet DTO AddUser: takes a DTO called UserAdd, and creates a new user both DTOs inherit from the class User, but have different additional fields. outline: class User...
How to unit test code that requires multiple side effects? For example, making an invoice. Simple action requires few thing to happen simultaneously: create invoice in db send invoice to backend print slip open cash drawer (if cash payment) (Simplified) I am having a hard time designing an object that does this and r...
In dealing with distributed data across Microservices, common solutions I've read for sharing this data are: a) using a local cache where the cache is updated from domain events coming from the service that owns that data, b) creating a materialized view, updating via domain events or database triggers. Say we have ser...
I have a use case that some external 3rd party vendor services send our service an item with price and a time range, the data schema includes : vendor_id, item_id, price, time_range it means the price for this item from this vendor is $price value during the time interval of time_range. Our service needs to support gi...
Imagine you have an application with the domain object User: public class User { public int Id { get; set; } public string Name { get; set; } public string Surname { get; set; } public bool Premium { get; set; } public int OrdersNumber { get; set; } } Your application ha...
I use python and javascript in my daily workflow. I am really excited about understanding c as I am drawn towards contributing to projects that are written in the language but even after weeks of learning I am not able to wrap my head around how certain things work in C Like, right now I am trying to figure out how to ...
I started using Pythons async features and want to fully understand their use cases. I see webserver like FastApi or Quart which use async features. How are they working different from webservers like Flask. I learned that Webservers start a thread for each connection and the thread then handles the connection and each...
MPL v2, GPL v3 and other licenses alike require giving users access to source code. For desktop applications - does access have to be provided through the user interface (GUI)? Or can it just be through program files? For mobile apps - is listing the names of libraries in-use sufficient? I have seen apps do this with ...
When developing a shared library in C, it is common to separate the "public" headers from the "private" headers. The public headers contain all the functions and types that are meant to be used by the end-user of the library (i.e., another developer), while the private headers contain internal implementation details. W...
In my machine learning pipeline, I have all the arguments collected into a dictionary. args = {'save_model': True, 'learning_rate': 0.01, 'batch_size': 4, 'model': 'my_model', 'momentum': 0.9, 'random_brighness': 0.5, 'random_flipping': 0.5, ...} Then I have a bunch of functions that take the entire args dictionary as...
I recently joined a tiny nonprofit whose flagship product is based on a decades-old C codebase, and I've been brainstorming with a senior developer about things I can do to help make working with all the legacy code easier. Here's the complication: this nonprofit has no resources to hire full-time developers (it's just...
I'm building an application with Google Firebase and Firestore that has its structure defined in the DB. This structure is not very big and doesn't change all that often. This structure is stored in different collections based on hierarchy going something like domain > chapter > unit, where each item has a list of chil...
I was trying to explain something to a junior programmer the other day, and as part of it I had to explain that: a method with 'find' as the verb in it, will either find an item and return it, or return null. a method with 'get' as the verb in it, will either return an item, or throw an exception if it is unavailable....
I am trying to organize my architecture following the clean architecture while using some common practices/frameworks. I'm writing in PHP, but have no problem with other languages. The flow of my app is somewhat like this: I got a front controller/bootstrapper which instantiates an App object. Inside de App I've got a...
According to my (perhaps incorrect) understanding business logic includes saving/updating entities in the database, as well as connecting with any 3rd party API's or using services and should therefore reside in the Model in MVC architecture. The controller should call model methods, and is responsible for application-...
I have following code snippet void func(int row,int n,std::vector<int>& buffer){ if(row>n){ return; } std::vector<int> new_buffer; for(int elm : buffer){ std::cout<<elm<<" "; new_buffer.push_back(elm*2); } std::cout<<std::endl; func(row+1,n,new_buffer); } the thing i...
In Martin Fowler's refactoring book, there is a code smell named "Insider Trading" which I don't understand: Software people like strong walls between their modules and complain bitterly about how trading data around too much increases coupling. To make things work, some trade has to occur, but we need to reduce it to...
For an app like Figma, for example, how do engineers deal with the various states a user can be in? A user can select an element. This element is now surrounded by a thin blue line to indicate it was selected. The user can then hover over another element. The thin blue line on the original element remains but the eleme...
I am planning software which includes a relational database of people. For each person, data includes such things as current employer, job title and phone number. Since these are things which may change over time, I want to be able to tell the difference between a fresh record (more likely to be correct) and an old r...
I'm building a single page application with a timeline and loading those objects in from a paginated REST API. I'd like to delete objects that don't exist in the backend anymore or that have been edited by other users, but the solution I can think of seems incredibly naive and frankly expensive. What I'm thinking of do...
sorry for the long question, but I love DDD but there is a problem I can't seem to resolve. We have a problem when adding business rules to the aggregate root. Our architecture is mostly like this when we make a query from the front-end : For a simple example, we have a Book we want to persist fetch it. The book has ...
I have an app where every object is checked based on various types of business rules. For this, i used multiple nested if-else statement which was done in one class. I am not happy with this situation because it became hard to manage. I tried to add some design pattern such as chain of responsibility and specification ...
This is a very generic question not much related to any language/protocol. I have a desktop application and a backend that communicate via TCP. Most protocol events are paired -- request/response. For example, I say "I want to create a secret chat with a person_id" (CreateChatRequest), and the backend replies with "Ok,...
EDIT: Perhaps what I am misunderstanding is that when it is said that the code we type gets turned into machine code of 0s and 1s. If these 0s and 1s are the abstracted representation of their electric states, then I actually don't have a question (it is just amazing that a compiler can take English and turn it into a ...
I'm working on a phone call monitoring project. The aim is to have one row in the calls table for each ongoing call. Each call instance may be updated by many different servers/threads as more information is gathered about the call. Each call instance (a row) is mapped to a Java object. When a server/thread needs to up...
I am currently rebuilding from scratch a product catalogue (to feed a shopping website). The existing legacy system is heterogenous, Long story short : The some products are stored in a FileMaker database (with a big spaghetti data model) and other products are edited as YAML files ... So my question is : what are the ...
Information given here adequately explains the "Stateless" nature of REST. Even going as far as to say: For becoming stateless, do not store even authentication/authorization details of client. Provide credentials with the request. Each request MUST stand alone and should not be affected by the previous conversation h...
I'd like to ask you if it's a good approach to have additional method in entity class that compares two objects? In my entity I have equals and hashcode @EqualsAndHashCode(callSuper = false, of = "uuid") This is legacy code. I need some other equals method to compare objects by all fields like Street, country itp. beca...
I find it strange that in the List interface are defined 10 methods of(...) static <E> List<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) instead of just @SuppressWarnings("varargs") static <E> List<E> of(E... elements){...} Actually, if I look at the implementation of the varargs versio...
System description This is a simple eCommerce application containing a Products inventory managed by an Admin. The Products in inventory/repository will show in the User App. Admin has the ability to mark ON/OFF a Product. ON = display in User App, OFF = do not display. Products are maintained in a single table (Produc...
(Using python) I am looking to generate a bytes (or can be string that I convert to bytes) that is a message to send over TCP. The format is [Header][Length][Payload]. Within [Header] is a [PayloadType] which determines the content of [Payload]. Equally, I am looking to take a response message of a similar format that ...
How does server-server communication compare to client-server communication? I'm wondering if there are any performance benefits when putting a GraphQL layer in between my client-side app and my rest-server. For arguments sake, let's say an endpoint on my rest api returns a response with 500kb of data. My client only n...
I've been trying to study some systems design materials in preparation for an upcoming interview. My current job doesn't really have to do that much for back of the envelope estimations. I've found a example design problem, specifically how to design Instagram. For the most part, it makes sense, but I'm stuck at a data...
I need to design a warehouse workflow: the cartons that enter, then the flow of a box, returns, porcessing of damaged good, cancellation at different stages, and transfer from a stock to another. Each operation can also change the product. What kind of UML diagram should I use for representing this kind of workflow? Co...
What I'm trying to build REST-API using Express and SQLite 5 to 10 authors should be able to post articles to /articles except them, no one is allowed to post anything My approach to build it authors are stored in the database password matched with regex and hashed with salt provide a login route for authors to logi...
I'm working on a security policy system design and I'm facing an existential question. Some of the policies have a model-level scope that could be defined like so : UserGroup x EntityType x AccessMode -> Boolean Meantime, I want to have finer policies that opperate at data-level, to restrain users to access only speci...
I'm reading now "Microservices Patterns" by Chris Richardson. At chapter 5 "Designing business logic in a microservice architecture" the author present the Ticket aggregate and its methods. While reading the "preparing" and "cancel" methods, I have noticed that there is a state check of the ticket before the event is p...
Our product is a C++ server component implementing a REST API. We have automatic tests that check whether the responses are byte-identical to the reference. The new requirement that came in is that the server now has to run on a different OS (built with a different compiler and standard library) too. In trying to get o...
Imagine I have an interface IHeapObject: interface IHeapObject { string Id {get;} SomeEnum Type {get;} } and it's implementation HeapObject: class HeapObject : IHeapObject { public string Id {get; private set;} public SomeEnum Type {get; private set;} public object objectLocker {get; } = new obje...
A simplified version of my problem looks like this: the database contains two tables: one contains account balances (Accounts) the other contains account withdrawal and deposit requests (Requests) the application consists of N identical workers that process these requests Two workers processing two withdrawals fro...
I'm studying some system design and came across an example of designing a web crawler. One of the requirements of the design is to have a URL dedupe service so that the same content isn't crawled multiple times. The example then goes into how to identify the dupes. They are expecting to crawl 15 billion distinct URLs. ...
What we usually have at work is an API that has a single consumer, usually a SPA web frontend, which is built by the guy sitting next to you. I completely see the need for authentication and authorization. What tends to happen in the controller methods though is a little insane to me. Basically the request is absolutel...
Does the ALU have its own memory or registers where it stores input operands etc. or does it only use CPU registers (that aren't only specifically used for ALU tasks)?
I already asked this question on stackoverflow -- I am posting it here as well, because I think many of you will have encountered an analogous problem. I would appreciate even a link as a reference, or the name of a relevant topic (even if you don't explain the solution). So, my reason for this question: I want a metro...
I'm trying to understand whether the Haskell and C++ communities mean different things by the word "functor", or if there's some underlying concept that unifies the two meanings. My understanding is that: For Haskell, a functor is a structure/container that can be mapped over, i.e. a function may be applied to the val...
My question is about Agile and if there is a known technics to split "equally" dev tasks between developers. In a backlog, at the beginning of the sprint, our devteam is asked to take tasks from the backlog, imagine a team (5 developers) and there is always someone "faster" and takes all "easy" tasks and leaves hard on...
I have this piece of code, and I've been racking my brain trying to think of a way in which I could factor out the if statements, mostly as practice to write code that is less conditional and more Object Oriented. String downloadPamphlet(String pamphletUrl) { if (cache.containsKey(pamphletUrl)) { Instant ca...
I have 2 classes that share some properties public class SportsUser { public string errorCode { get; set; } //the sportsuser and SportsAdminUser is from a different database hence the long and int difference public long userId { get; set; } ... } public class SportsAdminUser { public ...
It's an architecture where the client-side consumes data from, and sends data to, a back-end REST API. I would like to learn more about it, but I don't know the name of it.
I'm attempting to find some authoritative references to address this particular scenario. References to best practices guides would be helpful, specifications even more so. The scenario in question: A JSON API endpoint that, among other parameters, accepts a list of URLs. An example request JSON might look like: { ...
Note: All of this would be in AWS Hi everyone, What would you guys suggest for building something that: Takes in several different input file types (ex: csv, json, jsonl, xml, .gz, ...) That can be large (as of right now we know these can be multiple GBs) Maybe does some transformations / processing (requirements not ...
Consider the code snippet public interface Car { string getColor(); void Drive(); } public class CarWithAutomaticTransition : Car { public string getColor() { return "Red"; } public void Drive() { // Drive implementation... } } Now consider a car with a manual transmission. public inte...
To improve my command lines scripts, I want to add some optional console output, mainly for logging purposes. In my PowerShell modules, I use Write-Verbose for this (but it should be clear this isn't specifically a Powershell question, presumably, the situation is similar in other languages). There are plenty of sites ...
I'm working on decoupling a Xamarin (.NetStandard) solution. It was using DryIOC container but I didn't see the IOC structure from the dependency, as the projects are still tightly coupled. Three main projects go as below: MyApp -> MyCommon -> MyAPI namespace MyAPI { public interface IApiHelper //Q1 { T...
I have some components which require some asynchronous calls to be finished before those components are fully initialized and ready for work. I do not want dependant objects to know about these lifetime issues of their dependencies. How do you manage that?
I took a PHP test for NASA recently and thought I should have done better. I believe the issue is something I used to know about, but need a refresher in. I can't remember what it is called though. It is the concept that you have to check for null, empty, and edge-cases. No, it's not unit testing or anything like that....
Assume that were developing a cross platform graphics engine. Now we have quite a lot of low level APIs to choose from (OpenGL, Vulkan, DirectX 11, DirectX 12, ...). Now because of this, we are gonna use two APIs, Low level API (this is the API which the high level API uses and this is graphics API specific). High lev...
I have a C# class called FileTransferManager. Previously it took some parameters such as a username and password to connect to a FTP server. However now I have an additional requirement to support login using a private key. I'm using the Renci.SshNet library for the file transfers. This library supports both methods of...
Let's say you have a library StuffDoer which calls an external library MagicWizard to do its stuff. Then you add a reference to StuffDoer in UsefulApp. In some scenarios, referencing StuffDoer requires UsefulApp to reference MagicWizard directly (it "leaks"), while in some scenarios, it does not. I think in .NET it dep...
I'll explain my case as an example, but I think the problem applies to other web projects as well: I have developed a Telegram bot in Python and made its source public. Then, I have deployed the bot on Heroku, where it is running now. The question is, how can I assure users that the bot runs on the shared code and not ...
In the book Working Effectively with Legacy Code , there is section Higher-Level Testing in Chapter 2 Working with Feedback: Unit tests are great, but there is a place for higher-level tests , tests that cover scenarios and interactions in an application. Higher-level tests can be used to pin down behavior for a set o...
In my application I using SKPoinI as a key to store some small objects in Dictionary. SkiaSharp already used in this project for drawing and not need to be referred to only to allow SKPointI to be used as a key. At first look, it's a good and simple solution, but I not sure because as I presume that the SkiaSharp libra...
In our application some business logic execute when customer do an action on UI and some business logic execute on a cron jobs. I have read some where that we should only keep minimal business logic on UI and let the cron jobs do the heavy work, so that we can immediately show a message to the customer without making h...
One of our customers had a pen test performed on our application this week and let's just say it didn't go well. The main issue they have is that user authentication takes place on the client, rather than the server. The reason being that an attacker could decompile our (C#) application and build a modified version whi...
When to use workflows and what do you get doing the same thing in workflows that could do otherwise as well? Is there a benefit or its just an overhead? Are persistence, Transactions and SLA tracking really a feature that workflows can only help you with or be used for those purposes?
Lately I got in a discussion with my colleague whether the appsettings.Development.json should be added to the git repository or not. My considerations are: when a developer clones a repository to his development machine and builds the application, he should be able to run the application without any tweaking of the se...
I've read both visitor&strategy patterns are a good choice when it comes to export data into multiple file formats. I'd like to understand how to apply both so I've created a really simple dummy snippet : class SubWidget: def __init__(self, parent): self.parent = parent class SubWidget1(SubWidget): de...
I am currently working on a program that replaces the value in an array if the value next to it is the same as the current value. So If the array is [0,0,0,1,0,1,0], when the program runs it'll turn to [0,0,1,1,1,1,1]. Currently, the code works to an extent, it runs but I still get an “Index out of bounds exception” af...
I am trying to solve this synchronization problem in C to practice for my lectures of Operating Systems where we use POSIX and Linux. I've been trying for days to find an approach to this problem with no luck, and I can't seem to find similar problems. To be more specific, I'm failing to see which mechanism would all...
A lot of times there's a parameter in a partner API endpoint like success_url where you provide the partner API with an endpoint on your internal API to redirect the client. For example, on Stripe you can create a checkout session using POST /v1/checkout/sessions. In the body you send Stripe a success_url. You redirect...
I'm using unittest framework to run Python tests. Some system tests consist of a series of steps for a given scenario, and they need to run in a specific order. For example, I have a client application which performs offsite backups. System tests run on a live API in order to check high-level regressions in the code of...
I'm developing a microservice system, and I was wondering whether or not all services should share the same database under a single MySQL instance. I can't think of any meaningful disadvantages of doing so, and it would make backups simpler while also allowing foreign keys between services, making things easier. What's...
I have several configuration structures that can be JSON serialized and deserialized as follows: namespace config { struct Foo { std::string hostname {}; std::string ip_address{}; std::uint32_t port {}; }; JSON::Object serialize( config::Foo const& foo ) { // ... } config::Foo deserialize( ...
Presuming that I have written some sequential code where it can be broken down into multiple isolated tasks, it seems it might be efficient for concurrency to be introduced. For example print(expensive_calc_one() + expensive_calc_two()) Asuming expensive_calc_one and expensive_calc_two are pure functions but also comp...
I'm planning to start a new Spring Boot project with MongoDB. I'm very familiar with Spring Boot, but all of my past projects used MySQL. Each of my projects has the following directory, that holds the SQL creation/migration scripts: │   ├── db-scripts │   │   └── my-db │   │   └── schema │   │   ├── V20210...
I'm trying to figure out the best way to accomplish using Azure Active Directory Security groups to manage role assignments for an API. I'm trying to evaluate a few different options as well as poll to see what others were doing as solutions. Option 1 - Include roles in the token claims As far as I can see this would ...
I am developing an application that needs to programmatically determine the complete state of a DC motor, given a limited number of details about the state. For example: { voltage: Measurement(12, "V"), rpm: Measurement(5000, "rpm"), currentDraw: undefined, torque: undefined } This object would be passed to a ...
I'm looking for some advice on how to navigate the choppy waters of DevOps/SCRUM with in a team. Background: A team is very operational and has 3 products and 2 engineers, 1 Product Owner, 1 Manager (no scrum master, team lead, or tech lead) and their delivery sprint is 1 week. This team follows "you build it, you own...
I have softwares whose version number are stored either in a versionned commit file or in the code (main header file for example) Because of that before every release we have to update the version number and make a dedicated commit having a message like "Updated version number to xx.yy.zz". I find that these commits te...
I understand that if a system consists of multiple hardware-threads the scheduler assigns software-threads to hardware-threads. However, hypothetically, let's imagine a system that does only consist of a single-hardware-thread. Is the execution of multiple software-threads forbidden or does the program execute sequenti...
When using templates we can have T be any type upon class instantiation. If T is a specific type that needs to be handled differently or in a special way we can specialize or partial specialize that class template. What if we want T to be any type except for specific types that we don't want it to allow? With this in m...
It is my first question here so I hope I'm not doing a mistake. I see a plethora of questions in SO that people ask "how can I call an async method from a sync method?". Given my little background on the subject, I wonder why/when we need to call an async method from a sync method. Isn't to embrace async code always po...
Assume I have an API that indicates failure by throwing an error (because errors are not expected). In this situation, how should retry code be written? My first thought was to use something like this: int retry_count = 5; do { try { --retry_count; m_remote.communicate(); ...