instruction
stringlengths
34
36.1k
I will describe my problem with a very typical example, an e-commerce application. Says we have to manage Products, and we have 2 bounded contexts Sales, and Warehouse that store the product information. The Sales bounded context cares about price, product name, description. The Warehouse bounded context cares about si...
I face a problem in understanding how this situation can be traduced to an ER diagram. So I have an entity, let's call it car, and then, there are another entities, that are a type of car. For example, coupe sedan SUV sports... Now, I would simply put a column in car called type, if it wasn't because they have some dif...
I have seen a common design pattern where there will be a "lookup table" in the database like this: Color ColorId ColorName 1 Blue 2 Red 3 Green with a foreign key constraint on other tables, such as: Item ItemId ColorId 101 2 (Item.ColorId is constrained to Color.ColorId) In the code, there...
Suppose I have two threads, A and B. A is waiting for input, while B is waiting to be executed. All other CPU cores are busy with CPU-bound tasks. What will happen to A?
I'm learning and trying TDD recently, and I constantly encounter a situation when I need to ditch my current test because it's too broad. I don't know how to deal with it. To be more specific, let's suppose I have a class User, which contains a method getInfo. To follow TDD, I need to write my test first: @Test public ...
I dont exactly know, how to handle the problem, where one class uses shared pointers but I want to call its method from inside other class via this pointer. class Bar { public: Bar() = default; ~Bar() = default; void OnChange(std::shared_ptr<Foo> foo) { ... } } class Foo { public: Foo(std::shared_ptr<Bar...
I use the controller to extract data from a request and Use Cases/Interactors to validate the data. But can I use the controller to extract and validate the request data?
I wrote a prioritized/weighted left shuffle algorithm (the code is copied from my open source C# project Fluent Random Picker). What does that mean? You've got some values and each of them has a priority/weight (a number). The higher the priority is, the higher are the chances of the value being far on the left after t...
I want to specify in a BMPN model that a workflow starts whenever a specific service outside tells me to. What standard BPMN symbol shall I use for this? Think of it as a company wants to start a workflow only at night, so it uses an application and that app, at night, sends signals to our BPMS and we have to run the w...
I would like to ask a question about OAuth2 with an external identity provider. Assume a scenario with the following roles: Client A, Resource Server B, Identity Provider C. Furthermore assume that Client A is a web-application which makes the usage of a combination of client-id and client-secret useless (because secre...
I have a service that uses a package which is basically just a wrapper around an ElasticSearch index. I had to update the index as new data is added on a yearly basis. The source of the data needs to be added to the wrapper, which means releasing a new version. This does not at all change the expected behavior of the w...
Let's say I have a function in a class with the following signature: int fun(int x, int y,std::function<int(int, int)> funArg) The output depends on the operations done in funArg. My question is, how do you ensure that the code is tested in the right way? I can of course add a unit test with some random funArg, but as...
I have a function that performs a task which can either be performed immediately and without any blocking or it can only be performed after some delay. The caller of that function shouldn't need to care, that's why this function has a completion handler and will perform the task asynchronously if required and then call...
I want to adhere to the best practices and obviously encrypt the data sent to me by user. And I also want to provide the full-text search feature to the user (user can only search their own data, if that is not quite obvious). Example usecase: There's a messaging app which is privacy oriented (for the simplicity of the...
(This question is inspired by the SO blog entry Fulfilling the promise of CI/CD and this old question of mine: Why is it wrong to comment out code and then gradually remove it to keep track of what I've already done and what remains to be done?) The usually recommended software development methodology - if I understand...
On this book (Software Architecture, 10th Edition by Ian Sommerville, ISBN: 9781292096131), the following architectural patterns are presented (Chapter 6, 6.3, p175): MVC Layered Client-server Repository Pipe and filter architecture My question is: Is it possible to make an objective comparison between MVC, client-se...
As I understand, most of the business logic is stored in the value objects as constraints, like the price cannot be less than 0. But I have a problem where the value object depends on another value object as a constraint. Says we have 2 value objects BasePrice and Price in the Product entity. Both the BasePrice and Pri...
I am in two minds about sharing client / server errors codes. We are writing both ends of the system, if our API was external this would not be possible, but that requirement is very unlikely. So an idea would be to have some shared directory between client and server and then on the server: res.send(4xx).json({ error:...
To date, we have implemented a multi-repo approach in which each project, or for larger projects, each tier, has its own repo. Code is written in Typescript, Javascript, C#, PowerShell and T-SQL. We currently have 75-100 applications. Some are strictly server-side, some strictly client-side, most are mixed - a cli...
I was searching about simulation of artificial intelligence, machine learning and subjects alike and saw the news that some startups around of the world are using analog computers to simulate artificial intelligence/machine learning etc. Their argument is that (some) analog computers were not exact, even if you ran the...
I am using Domain-Driven Design with Railway-oriented programming as an exception handling method. Every value object will not throw an Error, but return a Result type to indicate if it failed or succeed. Here is my process: Command Triggered Loading data from the database to the domain Process changes Saving domain d...
I will describe the problem in a typical example Todo Application. The user can have many TodoList. A TodoList could have many Todo. The use case is "Add Todo to the TodoList". In this case, with my basic knowledge, I think the TodoList must have an add method to add the todo to itself. Since the Todo details like cont...
I have recently learned about the not-well-known and not-widely-used annotation @RepeatedTest that, as the name implies, repeats the very same test n-times. Baeldung provides a short guide to this feature, however; I have found nowhere to explain why this annotation exists in the first place. I initially assumed the re...
I am confused with wording used to describe UpCasting/DownCasting compared to wording used to describe level of modules. Imagine two classes: public class Human { } public class Doctor : Human { } If we talk about level of modules, Human class is low level module, while Doctor is high level one. Its how I understand ...
We're currently developing a product which will have a Web version and a Mobile version. At the moment, the plan is to have identical features on both of these. From a tech perspective, there is an opportunity to reuse a lot of the business logic code because both products are developed using a React framework which ha...
It's clear that an entity should never be in an inconsistent state; if a change would violate an invariant, a domain object should reject the change. But what if it's left in a valid, but inappropriate-for-the-input state? For example, consider a calendar aggregate that supports a "delay all meetings" feature – upon de...
I have some code and in it there are functions which can be run in one of two modes (in my case server mode and local mode). For example, most functions look something like this: def path_join(path_elements,run_type='local'): if run_type == 'local': path = os.path.join(*path_elements).replace("/", os.path.s...
My customer decided to have an automatic nightly build based on develop branch. We usually make a feature branch (and if it is necessary we provide a release compiled manually on that branch) and when work is done we make a pull request (to develop branch) The customer complained that the nightly build does not include...
I am trying to adpot a TDD process. I am a bit confused when it comes to testing an Api. I know for sure that the status and the response should be tested. But I am thinking if whether or not I should be testing the application state. Let's say that I have MVC design pattern where the Api is the controller and a CarSer...
Lets say we have an Webserver-Framework and a Database-Framework, and now i want to configure that Webserver and the Database, then it could look like the following class Start { public static void main(String[] args) { new Start().start(); } public void start() { var dbb= new Data...
I'm struggling on designing a solid architecture for my project. In particular, I don't know how to handle the communication between the models and the controllers. My goals are: Following the Separation of Concerns principle and have the models as independent as possible. Having internationalization support for the r...
The below ERD is taken from a professional architecture reference, however I have a concern in the relation between Customer and Invoice, I believe that relation between Customer to Order , and Order to Invoice is enough and that adding a relation between Customer and Invoice is redundancy. More over I am not getting t...
I’m currently working in C# and I’d like to write and extension method against a type. There is a small amount of repeated logic between classes surrounding JSON deserialization, using the JsonSerializer class from .NET, that I expect would need to be changed for each one if it were to be updated. The problem I’m runni...
I’m doing an task based application using Vertical Slice Architecture (VSA) and domain driven design (DDD). Tasks split into commands and queries and using Mediator pattern. Say I’m having an Order domain object but multiple commands, which do some work and based on that, has to create one or more orders in the system....
I have an ASP.net web API. I would like to call another API that has an authentication token inside my API. The code flow is as follows: My API is called → Get authentication token from 3rd party API → Call the desired methods from 3rd party API. The thing I can't decide is if my API is called 100 times, I will make 10...
I have to create a overview documentation for a simple PLC (programmable logic controller aka industrial automation controller) program (happens to be written in Step 7 but not really important). The structure of the program is simple. The functions i.e. "activities" are run one after another. Each activity reads a sp...
I would like to deepen the topic of multiple inheritance using Python and I usually find examples that are too simple. I love art and I imagined the following problem and I want to understand if multiple inheritance would be a good design solution for it. Let's suppose we have STL files (meshes) of 3D scanned faces of ...
I'm currently working on a design for a system that can service market data to external clients over the internet. The current solution involves consuming market data from a feed (Feed Handler), this data is then processed and used to produce 3 distinct data sets as shown in the diagram below. I want to provide a web s...
I have a bunch of scripts written in .bat files that I'm trying to implement into one big program using C#. These .bat files mostly do simple operations like copying files into network drives etc. Would it be better to implement the batfile functionality with C# or just call the .bat files using C# and System.Diagnos...
Imagine an http request in a RESTful API that needs to request the database to perform validations before proceeding, but some of those database requests would need to execute again if the validation succeeds. Assuming the validation is made in a separate layer, is there any design pattern that deals with this problem?...
I was reading about these patterns and noticed that they seem to be basically the same, but in different contexts? If that's the case, why isn't Front Controller just considered as a Mediator pattern but applied in the context of web applications?
I'm writing an SDK for the European Space Agency's DISCOs API. This has around 10 endpoints with different sets of query parameters, each of which returns a different payload type with different link parameters which will also need to be resolved. I explicitly don't want my user to have to construct query strings thems...
Our new team suffixes class names with API to indicate that they encapsulate RESTful methods. Eg: "PaymentTemplateAPI", "FeeTemplateAPI" classes. I find it odd since API is a general term that refers to any API/method created using any architecture style (REST, RPC, etc). I would suggest adding suffix "RestAPI" to conv...
I am part of a small project that is doing some research code in C++. Our work involves a lot of mathematics and due to its nature we often need to temporarily use other people's code/libraries. To speed our own iteration times we designed a template based interface that allows to treat almost any vector type, e.g. Eig...
I am creating a web application which has three distinct components as far as I understand. A Nuxt frontend, and Spring Boot backend and Google OAuth2 for authentication using OpenID Connect. Nuxt can be extended with Nuxt-Auth which has support for OAuth2. I just need to give it my Google OAuth2 Client ID and two endp...
If I have two boolean variables B1 and B2 whose value combinations cover four independent behavior functions (MFF, MFT, MTF, MTT), then how many concrete strategy (design pattern) classes should I create? From the single responsibility rule, it seems like I'd need a strategy interface with a single method, and four con...
Here is the scenario: Let's assume that we have a Telephone and a Driver. Here is the definition of the classes (Pseudocode): Telephone: { Id: number, [Unique] TelephoneNumber: string } Driver: { Id: number, Name: string } Telephone Number has a unique constraint. The driver has a relationship with the teleph...
A modern world is full of gigabit/sec switches. There are 2^32 octets (bytes) of the sequence space as per TCP standard. Let's calculate. 1_000_000_000 is 125_000_000 bytes. Conceptually, each byte within the established TCP connection has its own unique sequence number; uniqueness is a must here because without it the...
I've recently found myself using a generics with constraint that a type should inherit from a specific base class, but now I've just realised that this is redundant and unnecessary because the following code: public class SomeClass<T> where T: SomeBaseClass { T SomeProperty{ get; set;} } can be replaced with: publi...
I know that P2P sharing is copying the exact content between the peers. Everyone has the same data. Let's assume the content is very important and I don't want anyone to distribute outside the group. only those who got access to the material can only download. When anyone downloads the content. The material gets marked...
My specific problem is that I have a vertically scrollable window into which I need to place rectangular <div> elements that are locked horizontally and have different widths and heights. Basically each <div> has a different start/end horizontally. The order in which the <div> elements gets placed is based on priority....
In my current development task, I want to validate whether a string is in JSON format or not. When I checked for solutions from resources like StackOverflow I saw many of answers are as below, try{ JsonParser parser = new JsonParser(); parser.parse(passed_json_string); } catch(JsonSyntaxException jse){ System....
My first thought was that I'm "serializing" the complex object, but from what I understand that means I'm reducing it down to a string or binary format which could be passed over a network. While what I am actually doing is converting a complex object to more primitive types like list, dict, str, int, float, etc. The c...
Hello I will try to explain what is my actual understanding of tests and why I have problems to grasp it's utility. Even if I try my hardest to understand the concept of TTD, unit test, integration test, etc. From the most articles that I read it explain HOW to do it (with a trivial example or a framework) and sometime...
Given the classes: public class SocialNetwork { private final Map<String, User> users; ... } public class User { private final String user; private final LinkedList<String> followers; //stores the users that "user" follows ... } I was wondering if it is considered a good design practice (and why) to s...
A Facade is a higher level API over a whole subsystem. A God is class that violates SRP. Where do we draw the line? Does the following code represent any of the two: enum UnitType{Demon, Paladin}; namespace demons { bool are_scary(); static unsigned numbers; void attack(); void phase_out(); } namespac...
I hope I can explain my question clearly. I'm planning to do some real time 2D grayscale image acquisition, and after reading some articles, I noticed that many are using buffers or multithreading or even parallel processing. Below top shows how in single threaded control perform one task at a time and bottom shows how...
I'm working on a project which utilizes DDD, Hexagonal Architecture and Microservices. While working on StorageService, the implementation was quite easy since the features were: CRUD of media files automated backups There was just one aggregate root, and nothing fancy about it. .. but now, I'm digging into ContentSe...
I have some issues selecting an appropriate naming scheme for GitHub repositories that belong to the same project. The main package repo relies on additional repos to generate documentation or run tests. During development on the local machine, those repositories import one another (located in the same root directory)....
I have a monolith CRUD application with a feature - possibility to export some DB entires to an Excel file. The export is done within a background task. Often, however, when user presses the button and expects to get a link with completed download, they may trigger a crash for the server where the webapp is hosted (not...
Is it OK for an API to accept either an object or an array on the same endpoint? I want to allow the user to post multiple items at once. I am thinking of creating a different endpoint, but then it gets hard with the semantics. Maybe prefixing the relevant handler with bulk would do it. I thought that maybe the user ca...
I have a question regarding the modelling of bounded contexts and the context mapping. I have to evaluete and document an existing architecture where two bounded contexts are exchanging information with message events (domain events). Has the bounded context which sends the events an open host service? Or am I getting ...
I am developing an E-Commerce Web application using C# (back-end) and JavaScript (front-end) for a computing shop. This application mainly displays each stored computer, and all information about it (model, price, image, speed, ...). A computer can be a desktop, a laptop, or a server. Each type of computer may have add...
Usually, unit tests are built in a separate project/executable. Ideally, components under tests should have a small number of mockable dependencies, allowing us to do this, among other benefits. But this is sometimes hard or requires a lot of effort. Some examples are legacy code, code that depends on elements that are...
I have a list of python dictionaries (let's assume each dict is flat for the time being). The keys are all strings and the values are strings or real numbers. I would like the user to have the freedom to filter this dict in which ever way they choose to, using some kind of query language. The query can contain nested '...
I have looked at the source code of some standard C functions and wondered what the reason is for null-terminating a string other than to find out its length. e.g. The strlcat() function which is defined in the string.h header. size_t strlcat(dst, src, siz) char *dst; const char *src; size_t siz; { regi...
I find a lot of resources regarding strong consistency versus eventual consistency, and when to choose one or the other. I'm wondering how and when you would have both together. Consider this specific scenario: Order service receives and stores order to database. Order service sends OrderReceived message on the messag...
I have the following architecture: Database (Postgres), Batch(java app - long running operations that delete, update, insert lots of data in the database), Rest API(java app - provides rest services to the front end). The problem is that when the Batches starts to run this spikes the utilization of the database to 100%...
I have some .env files for my backend application and the usual recommendation is to put all .env files in gitignore to not share it in the repo and use something like Github Secrets to store the .env files. That sounds a good thing to do, but if I have a private repo, where only people that should know the .env files ...
I have a service class that does some magic. I want to introduce a new type of functionality - raise an event. I am absolutely sure that decorator pattern is great for this scenario. The problem is that the variables I'd like to pass as an event arguments are created only in that service class function. These variables...
In microservices oriented architecture, service A receives a file and stores it. Later Service A has to pass the data in the file to Service B. We have a choice to send the data, as: batches of rows to Service B's Api or using message queue share the file URL with Service B. Does number 2 seem a reasonable choice? It...
I am building a microservice app where the client sends requests through REST APIs to the backend server, and the backend will communicate with other services using gRPC. I am aware that this is synchronous and is an anti-pattern for a microservice app due to the tightly-coupled attribute. My question is if I were to r...
We are building a multi-device (different vendors, different types) manufacture machinery where these device work together orchestrated by our software and operated by a human being to create various products. We are currently working on establishing an architecture for handling many different devices with an outlook o...
I prefer to create linear git history, which can be fast-forward merged. This was a technical requirement at my previous job, which used BitBucket and required all PRs to be fast-forward-able. We had to always manually rebase onto latest master. A new company I recently joined, using AzureDevOps, likes to have small PR...
I have a bean which executes a method doStuff asynchronous, which of I am uncertain what is the best way to test the logic of that method doStuff. public class MyBean { private final ExecutorService executorService; @Inject public MyBean(ExecutorService executorService) { this.executorService ...
I am maintaining a FOSS library which, for the sake of discussion, consists of a small .h file and a larger .c file (plus build-related files, see below) I've been requested to offer this library as a single header file. My instinct was to just refuse, as one could simply include both the .c and and the .h file, but I ...
I am developing a web app along with a backend API. The backend however must talk to other services, some of which are internal and others are not. In an ideal scenario we would spend time and have a local copy of all services running, but this is not possible due to; some services being 3rd party and other internal se...
I've read the questions regarding the use of random values in unit-tests and, well, I still don't quite understand what the argument against random values is. I'm trying to understand because I've had an entire course dedicated to testing while I was doing my Masters in SE. The course focused heavily on random value ge...
I'm studying systems analysis in my CS class and we've just been taught about Gantt charts, CPA diagrams, and modelling. I'm a bit confused regarding data modelling and process modelling. From my vague understanding, the former involves visual illustrations while the latter involves written ones. Reading up on it seems...
Short Version If we had an application based on a state machine - transitioning between states to run the application: is repetition, and in fact the entire state machine, based on the presence of an event loop? Something like: void Main() { while (_currentState != State.Exit) { switch (_currentState) ...
To illustrate the problem, I'm defining a PositiveNumber class that is a subclass of a Number class. As Python doesn't support type casting, I'm defining the from_number as a convenience method I can use to cast one instance to another. This method is common to all subtypes of the Number class so I'm putting it into th...
I am in the process of implementing onion / clean architecture, and would like to understand better how and when to map to my domain entities. So if we take a specific example where we have a Post and we would like to update a status on this object. Am I correct in thinking that when I receive data in the controller I ...
Assume there is a distributed system which works on the principles of eventual consistency. Let's consider a scenario where I update my profile picture using my phone. If I log in using another system, let's say my personal laptop, it should show me the updated profile picture assuming it routes through the same data c...
Summary: In an organization that wants to use an agile/Scrum software development process, but that also has a large production support / operations burden with an expectation for quick response times, what's the best way to ensure an adequate level of production support / operations without throwing all teams' sprints...
I'm looking to build a service that interacts with an existing web application's database. The service would retrieve data from an api for which the web application users own an account and warehouse/refresh this data for them. I'd like to make sure we can handle potentially large amounts of data for each user. Current...
I've started learning Python recently, and there are some topics I cannot really understand. One is the usage of the decorators in user defined objects, or encapsulation more generally. I mean, let's consider for example: class Dog: def __init__(self,name,age): self.name=name self.age=age Ok so now I ha...
I need transactions in my service to ensure data consistency. I don't know what the best layer is for transactions to be created in. The goal is to have all business logic in a single layer. First, some example business logic: There are the entities of person and hobby. Each person can have multiple hobbies. This means...
I'm working on a somewhat typical notes app that I plan to create with React Native. Since the usage involves a lot of typing, it makes sense that there should also be a web version that users could open on their desktop. Now, if the app was mobile-only I was planning to store the data locally using SQLite and let user...
The Wikipedia article on the Composite Design Pattern includes the following diagram: As you see, there is an association relationship which is child 0..* – 1 parent. However, given that: a Composite class is a Component as well, and every Component has a parent (a Composite)... Doesn't this force an infinite tree o...
Below is an excerpt of Fundamentals of Software Architecture, page 65, which I am reading: The instability metric determines the volatility of a code base. A code base that exhibits high degrees of instability breaks more easily when changed because of high coupling. For example, if a class calls to many other classes...
The Wikipedia article on the Composite Design Pattern includes the following diagram: As you see, there is an association relationship which is child 0..* – 1 parent (association). However, shouldn't it be a composition relationship instead (filled diamond)? To me, it is nonsensical to consider the identity of a node ...
In my library (DLL), I have extensions for List like the next one. <Runtime.CompilerServices.Extension> Public Sub Store(Of TVal As IFullyOperable)(items As List(Of TVal), w As BinaryWriter, closeAfter As Boolean) Try w.Write7BitEncodedInt(items.Count) items.ForEach(Sub(i) i.Store(w)) Catch ex A...
I'm starting a new project in which we will use Client Side Rendering for the frontend. This is my first time working with this kind of technology and I was wondering which would be the best approach to develop non-regular users components (for instance, fragments that only Admins or Moderators should be able to see). ...
Ok I have a bunch of components that all have the same logic but have different css classes. So I wanted to create a sort of factory function that takes the names of the classes as its argument and returns a component. Here is a very simplified example: const buttonFactory = (classes) => (props) => { // ... some logi...
First of all I am not sure if this question should be here or in stackoverflow. I decided to post it here because it is not a coding but architectural challenge. Introduction I have a data base design for an HRM system that I have come up with. For simplicity, I am excluding lot of fields that is not relevant to this q...
I'm wondering if the following approach can be used in order to increase parallel processing of Kafka messages. Suppose there's a topic with N partitions. At some point the system hits a bottleneck in terms of parallel processing (N partitions are not enough anymore) and the order of messages is important so adding mor...
Context Let's say I have a Shape class (I'll use C# for the code snippets) that represents a 2D shape, like a triangle or a circle. These shapes have an area, so I'll include a method for calculating it. Since I only care about the calculations, I don't want the Shape class or any derived class to contain any data. Ins...
I am currently planning to create an application. So far I have always been using the traditional username/password approach. But I would like to get rid of passwords for user authentication. This would avoid to worry about weak, stolen and forgotten passwords. I want to create a passwordless signup and signin with mag...
I would like to have type-safe access to items in a collection with polymorphic items at compile-time. For this, I set up the code below as a proof of concept. Passing the DataItemProps instances to the GetValue, SetValue methods of the Data class, it is possible to resolve the type of an item during compile-time, allo...
If we use both, epics and user stories, should all user stories be linked to an epic, or could some stories stand independently on their own? It's more or less a question of formality in order to keep the process clean: in such a context, can I let a user stories stand on its own without linking it to an epic?