instruction
stringlengths
34
36.1k
In microservice architecture, let's say I have 4 services that will need file upload/download feature, I have two options for this: I can create another new service(5th) to expose an file upload/download API. But when it comes file download authorization, the download privilege actually depends on the other 4 service...
Is it a good idea to mark a function const from clean code perspective if it change other objects' states? I'd like to know what is the experience with this or is it considered a bad practice for any reasons?
I have the request to integrate my Python server application (Flask/waitress) with Kafka. That means that it should frequently poll a certain Kafka topic (on the order of minutes) and process all new events. As the application is deployed in the cloud, I am looking for a scalable solution so that different events could...
I have a project in which I have to manage projects, invoices and orders to providers. So I think that I can define three bounded context. First bounded context: Projects. Second bounded context: Invoices. Third bounded context: Orders to providers. Well, my doubt is how to the invoices of a project, because they are d...
I have two versions of an API with similar but slightly different response structure. We are currently using V1 of the API and will gradually move to V2 soon. The switch has to done using a feature flag that gets triggered remotely. Our class look like this, @RequiredArgsConstructor class ServiceA { private final ...
Sorry, I would have left a comment on the other question, but I don't have enough reputation. I have the same problem as in this question: How to specify many ids and their variable name in a REST API request? I have a big list of 800+ employees. (I have to show them all at once. It's required by the customer.) The use...
We have a largeish .NET Core project which uses Mediatr and EF Core. Many of the queries look something like: public class GetSomeInformation : IRequest<string> { public int DocumentId { get; set; } } and we load the entities with AsNoTracking to avoid issues with attaching duplicate entities if we need to update ...
I am trying to design in DDD the management of orders to a privider. The order has to have the information of the provider to which i will order the items. Later I will add lines to the order. This lines will need to have information of the provider, but different than the data that I need for the provider of the order...
I am trying to create a simple demonstration of using 'parallel LINQ' (PLINQ). I have two versions of my task, in C#: var result = Enumerable.Range(1,1000000).Where(x => IsPrime(x)).ToList(); var result = Enumerable.Range(1,1000000).AsParallel().Where(x => IsPrime(x)).ToList(); and use a System.Diagnostics.Sto...
C++ and Python are the only two languages I know supporting multiple Inheritance. Other object oriented languages I have seen like Java and Ruby do not support multiple inheritance. Even the front-end scripting languages do not support multiple inheritance. According to Wikipedia, Multiple inheritance allows programme...
We know the «Gangs of Four (GoF) Design Patterns» have 23 Design Patterns. But I wonder: are design patterns limited to these 23 or do we have more? And what would be the sources for other design patterns?
Given a (Django) web application following the model-template-view model, when returning a template based on an object should if-else logic be in the view or the template? The API endpoint (view) gets a request to display a template based on an object (model). Some parts of the template are conditional on properties of...
Our travel industry client, operating across three continents and several countries, wants to standardize the process of choosing travel packages, air routes, hotels, and hundreds of other travel options. Today, local travel agencies decide themselves what they want to offer or not. The idea is to let them make decisio...
floating point representations## exponent == 7 bits ,mantissa == 8 bits 2044    = 0 1001001 11111111 2045.5 = 0 1001001 11111111 why is this happening?? what is the error? Is anything wrong with the conversion?
In the book Operating System Concepts, In the summary it states: A monolithic operating system has no structure; all functionality is provided in a single, static binary file that runs in a single address space. Although such systems are difficult to modify, their primary benefit is efficiency. A layered operating sys...
I have a job system that has two different types of dependencies per-job: Jobs can rely on other jobs to be completed first, but this is optional Jobs have read/write dependencies (shared/exclusive) that are used to restrict which jobs run at the same time. This is currently represented as a series of type hashes for ...
I have a number of non-nested if statements that look like this: if (!bytes[nameof(PropertyVersion.Price)].SequenceEqual(dbBytes[nameof(PropertyVersion.Price)])) changes += $"Price {TextHelper.AssessValueIncreasedOrDecreased(dbPropertyVersion.Price, propertyVersion.Price)} from: £{dbPropertyVersion.Price:N0}. "; if (!b...
As a design priciple I was taught: Programe para una interfaz, no para una implementación. Es decir, no se deben declarar las variables con el tipo de los herederos sino con el tipo de los supertipos. Translated: Code for an interface, not for an implementation. That is to say, variables should not be declared with ...
I'm sorry if the title is confusing, I don't know if what I am describing has a proper name so let me describe... I have an algorithm which contains quite a bit of nested if/else if/else logic for detailed analysis of input data from the database. This is business logic that's inherently quite convoluted so there are o...
I’m using a hexagonal/clean/ports-and-adapter architecture. For the sake of simplicity, I’ll only talk about domain and infrastructure here, where the infrastructure has dependencies on the domain but the domain is unaware of the infrastructure. My application (infrastructure) receives events. The infrastructure layer ...
I am seeing this example in the Microsoft documentation: Here we can see how OrderItem has a reference to the ID of the product, it is the first option that sure people uses to think, me too. But I was thinking about this and I was thinking, why isn't OrderItem a value object? If I use the ID of the product, I have th...
I'm reading OO DDD slides from Robert Brautigam, who is quite active here so I hope he can personally answer as I quite agree with his personal understanding of DDD, and approach of having a more object oriented approach instead of a service one. In our apps we have an awful lot of this: class OrderService { OrderRe...
I'm new to queuing and looking into options that could be done operationally. I'm sorry if I have any conceptual misunderstandings related to queuing. I watched this video where the presenter made a point that one benefit of SQS over RabbitMQ was that if you ever had to do maintenance on your RabbitMQ server that you c...
I'm working on an app that will focus on P2P communication via WebRTC. Part of the app's functionality is discovering other devices in an x mile radius and then being able to initiate communication with them. The most straightforward way to do this is to send the raw locations of all the clients to a server and then re...
How many dependencies does a unit test have (that are not mocked)? My understanding is that a true "unit test" has zero dependencies, with all of them mocked (or none in the first place; pure functions.) (Unit tests are excellent for pure code, but in a real application most code is not that pure. They work great for s...
As has been covered to the point of parody, heavily object-oriented languages, such as C# or Java, tend to lack the feature of having functions as a primitive type. You can argue about whether or not their functions are first class, but the pattern is always that you cannot reference a function on its own; It must alwa...
I have products saved in my database that my system fetches with the following structure: public class OriginalProduct { public string Id { get; set; } public string Name { get;set; } } I need to enrich the product with additional fields like a price, stock level, images, description etc. These are all fetched f...
I'm sorry if I'm using any wrong terminology here. I'm trying to design an architecture where there can be big and small tasks (e.g. processing big or small images). Big tasks can only be handled by big boxes while small tasks can be handled by either big or small boxes. The big tasks can finish while there are still s...
I am stuck with this particular problem. To give context to the problem, I am developing a mobile app which helps with loading dangerous goods onto a truck. Ignore the size and weight of the dangerous goods. Some dangerous goods cannot be loaded onto a truck unless one of the goods is in a specific type of box. For exa...
I am reading Tanenbaum's Modern Operating Systems. I want to understand a particular concept regarding processes and blocking system calls, specifically with regards to I/O. I assume threads might complicate the discussion somewhat, so please assume that I am asking about single-threaded processes only. The book states...
I am working in a database that has a hierarchy of Companies (From location-level all the way up to Top-level parent company). I am designing a system within that to provide a "subscription" mechanism that has implied inheritance. So for instance, Let's say you have Parent company A that has a subscription to service S...
I have a pretty simple domain model. Basically users, companies and groups. A user can add members to a group and remove them. But the user can only do that for his own company. Where do I put the check that the user is only adding or removing users from his own company? I've got the Group Aggregate which has 2 methods...
I was trying to use the state pattern in a DDD aggregate, but I was thinking in the following alternative. In sumary, the state pattern controls what actions can be done in each state. This makes to create one class of each possible state and implement it. So if I want to add a new state I have to modify the code. I wa...
NOTE: This question is reposted from SO because it violates community guidelines for being opinion-based. I have two classes that are similar in nature but they have different functional signatures. I am considering between having two interfaces vs having one. Let me illustrate: Approach 1: two interfaces public interf...
I'm a junior web developer. My current work is on a form-based server side web application. It was set up using jQuery. I'm now the primary person working on it. In a previous job, which was more front-end-centric, they decided to move away from jQuery. It was not needed anymore.* I heard it elsewhere as well. But I so...
I've found this pattern useful, and am trying to classify or name it. Basically, that: A task should be performed by different strategies, depending on the context. Each concrete strategy implements a common interface. BUT... caller doesn't choose the strategy. Instead there's a priority-ordered list of the available ...
This seems pretty newby question but I still can't find a answer I'm ok with. I'm doing a microservice and decided to have a Message as an aggregate root. This Message represents a kind of announcement and incapsulates distribution rules. From the other side I have a MessageHistory agg root to track creates\updates whi...
In a typical DDD layered architecture (application, domain & infrastructure layers) you'd generally declare interfaces in the domain/application layers and implement infrastructure-dependent (e.g. file system, network, third-party libs, etc.) implementations in the infrastructure layer. For instance, a ClientRepository...
I'm trying to understand the size of a micro service. Fake situation: Data is read 1,000,000 times for every write. So when you scale out you generally only care about scaling out for the 'GET' requests, not the POSTs. Should POST and GET be separate deployable applications? PRO: Spinning up a 'GET' box would be faster...
I was thinking in the common example orders, that can be in different statates. From create to pending to accept, accepted, sent... and so on. But the order has data too, for example the client, the address to deliver, coments and another information that can be modified depending on the state. For example, the address...
On Stack Overflow I frequently see questions with code in the following style: function funcName(parameter) { let variable = parameter; // rest of function uses variable rather than parameter } Is this just some cargo-cult practice that some programming teachers pass on, or are there coding style guidelines that a...
I am faced with an interesting OOD problem: I have an interface with 3 methods: interface TestInterface { String action1(); String action2(); String action3(); } and 3 classes that implement this interface, so I have a very simple code: TestInterface testInt; if(something) { testInt = createObject1(); } ...
What are the best practices that I can follow that can simplify or help abstract out entity modeling when there are many similar but different entities? I have a large game system with different types of accounts representing an end user, but they are all distinct & isolated. To name a few, The system has a concept of...
we have a microservice architecture. There is an API Gateway that acts as entry point for a External System (SAP) It is clear that SAP should connect with our system using the API Gateway. But, in the case a microservice (Costs API in the diagram) wants to consume some API inside the external system, it's a good choic...
As a university student who just have been learning programming for a year. After I learned about the concept of state machine and the pure function in functional programming, I suddenly got an idea about combining them together as a programming style. Everything is either a state machine or a function. (So all the va...
Imagine a simple set up of an API and a 2nd service, where the API pushes some msgs to the message queue and the service pulls them and processes them. Now, if an error occurs while processing a msg, there's no straightforward way of sending the error upstream to the API, so it can bubble it up to the client. The firs...
With interface injection (wikpedia) we have a method to set the dependency on the client as part of an interfase. public interface ServiceSetter { public void setService(Service service); } Why do we need separate interface for the setter method instead of just having it just in the client class?
I'm recently learning the programming language, and I wonder how compilers work when the language itself does not allow recursion, like how the compiler or the runtime checkers makes sure that there is no recursion. I learned that compilers don't need to understand recursion when translating the code, but how does one ...
I want to make sure I understand the concept referred to by alignment: Is it just a way of making sure that you never have a non-integer number of words? The wikipedia page says in order for an access to be aligned, the address has to be a multiple of the datum's size (which I interpret as number of words; as in, a 4-w...
Imagine a queue system with different consumers - some are low cost whist (like 'reserved/spot' instances in the AWS world) others would be high cost. The system should ensure the messages are processed by the low cost consumers when available, but if they are unable to process a message after a certain time period th...
I work on a code base which was started by a small team. Over time, more features were added, and the team has grown significantly. Everyone has added functionality here and there. There is a rather central struct which is used to keep track of intermediate results as it is processed through the system. It started out ...
I have an array of entities which have an id property: entities: {id: string|null}[] = []; All items in the array are guaranteed to have id !== null and the array will not exceed 100 items. Now I may want to find a specific item based on a condition: const id: string|null = condition ? value : null; My quesiton is: I...
In my team we are currently building an API gateway, where the client can authenticate themselves with an API key. Naturally the authentication may also fail, which produces a message in the log. Should this be logged on the 'error' or on 'info'-level? I have a couple of arguments for both, but am unsure if there is a ...
We are rebuilding an on premise application using microservices and are wondering how to implement data autonomy given certain constraints that we are facing: The application is built around a set of files that it needs to keep in sync with the cloud service. We have very limited bandwidth available, and so we have to ...
Two developers (front-end and back-end) are working on one User Story, while the front-end is dependent on the work of the back-end. What is the best way to handle this dependency regarding the branches: The back-end creates a branch, works on that, and the frontend continue to work on the same branch. The front-end ...
I started a project awhile back and have made a lot of progress since then. In the beginning I didn't think much about restful architecture and how I'd serve data to the frontend. Now, however, it seems the way I am doing so isn't exactly like other projects I see, so here is my question. What are the main issues with ...
I have seen in mainly high level languages, but also in lower level languages, the use of option names as strings to specify one of several fixed options, or as flags, or more generally, code using strings to communicate with other code. In GTK, for example, g_signal_connect() uses a string as a signal name to specify...
I made a patch to a programming language run-time to cache the results of hashing a string in the string object, so that it is just retrieved the next time it is required. However, I'm not convinced there is any worthwhile benefit, and the feature comes at an opportunity cost. Heap objects have only four pointer-sized ...
I am currently building a C# application that gets JSON data then it calculates something then stores the results in a database, what is the proper way to design the application. This is how it's now I have a static class that gets and parses the JSON, then stores it in an object and all objects are then stored in an ...
I need to rewrite my project due to many underlying issues causing errors and I started following clean architecture by Uncle Bob (I read the book). I created my domain, infrastructure, application and interface-adapters. In my domain directory I have an entity called TreatmentPlan containing all the business logic. I ...
I have this: Class Order { long ID; ... } Class Item { long Id; IdProduct; decimal Amount; ... } Perhaps I misunderstood what means bidirectional relation in DDD, because I have read that if it is possible, it is better to have only navigation from parent to child, and not from child to parent...
I developed a big(ger) project, which is in use already and grows, gets altered, fixed, etc. every week. Until now I am the only developer. Since the team has to grow, also we will be more developers on that project. The code is mostly self-speaking or commented on the darker places ... But I guess an experienced devel...
Suppose you have a ERM containing about 40 Classes / Entities. Most of them in quantified relations to others, some of them as standing there alone. How to deal with a very often used relation/attribute called image of type Image? I am afraid, because I have so many entities that own an Image the diagram will be clutte...
From the answer to Must the use cases extend the entities in Clean Architecture? I have known that the use cases must NOT extend the entities. It's fine, but what do I have to do with the properties of entities which are depending on the application? Very strictly speaking, these rules (note: the enterprise business r...
I'm trying to make sense of how to handle events in my server in a neat way. I'm creating a Whatsapp chatbot that receives messages via webhooks at a certain endpoint on my server. It doesn't seem right to me to handle all logic at that endpoint, so what I'm thinking of doing is passing the data to another endpoint (so...
I understand that credential leakage occurs reasonably often due to people forgetting to .gitignore a .env file I'm building an application in VueJS and right now I'm storing some S3 credentials as environment variables in order to retrieve and access some data in the site. Is there any way that this can expose credent...
I'm looking for specific software design patterns that can help me understand how versioning of the same entity where the domain logic has changed between the versions, can be solved. The following example illustrates a use case for this problem. Let's say we have the first version of a form that users are required to ...
I'm currently developing a chatbot that will be used for booking trips. The particular party I'm interested in for now is the rider. I'm using AWS's DynamoDB, because it seemed to be the most flexible and fast for a system like this that is likely to get lots of concurrent traffic, and in which records won't have well-...
As implied by the title of the Q, I have a few entities and need to keep them as constant objects in a C++ project. Each entity contains very complex data structures (lists of enums, maps of maps, etc.). In addition, it is possible in future to have more entities for extending the project. For keeping the complex data ...
Let me clarify on a bit of an abstract question. I'm about to develop an app, through which users can capture and store images. Commercially, the main cost here that springs to mind is storage cost. There are platforms (e.g. facebook, dropbox, instagram) that may expose an API to allow consumers to upload images. Which...
I am working on an android application with Bluetooth iot devices. Theses devices sends broadcasts periodically in the form of 30ish bytes containing various information. Some of the bytes have specific values akin to enums or flags and some have fixed values like the product type which is always the same. For now I ha...
I am currently working on a web product where we have a testing strategy that includes end-to-end testing. Our tech lead is of the opinion that each e2e test should only validate a single feature. For example, we would have a test for creating an account, a separate test for logging in and an other separate test for up...
I just started as a junior business analyst and working on defining the requirement for an already existing system, so I am gathering the requirements for a just added service. One of the requirements is that an invoice file should be able to be downloaded as a csv and xml, and not only as a excel file. I have a hard ...
We are using a client library over Memcache. This library has a lot of logic for Memcache client and is indispensable in current form. One of the API of the library is put which internally just uses an async mechanism to write to Memcache. There is no way to know if the put actually went through. Changing the library i...
A lot of sites will save the progress of the creation of an entity or some process. For example, stackoverflow will allow you to draft a question before you post it. If StackOverflow used DDD, I would assume that the Question entity would only be valid if it had 1) a body and 2) a title. So there must be some precursor...
I came across a class that implements a kind of "strategy pattern" with a concrete implementation defined inside the main class as a template method. #include <iostream> struct ObjA { int a = 123; }; struct ObjB { int b = 456; }; class Algo { public: void stratA(const ObjA& obj) { strat<ObjA>(obj...
I have nearly 300 devices interconnected in the local ipv4 network and would like to discover each other somehow. At the moment, I'm using mdns announce to achieve this (using avahi lib). This solution works up to 50 devices, but it goes more than 100 I started to face some flooding of avahi announce messages in the ne...
I have an intuition, that I'd like to read what others have talked about. To me, it seems fairly intuitive that when you have a function which is called multiple times with the same arguments, it would be better to create an abstraction which doesn't require arguments, to avoid duplication. So for example, if I have: g...
In DDD, the model has to implement only the bussiness logic, and it has not the responsability about another things, like persistance. So I was thinking that perhaps is in the application layer a good place, because it is the layer who get data from the database with the repository, call the methods of the domain and p...
I have an interface that looks like this: public interface IInterface<T> where T : IParameterType { void InterfaceMethod(T param); } And a lot of implementations of this interface, each with a different derived type for T. I can't change the interface. Now I want all the implementations to call a common line of co...
Are there any formal techniques/tools/approaches to software defect investigation? For context, I'm looking at ways to approach intermittent failure in large distributed systems with many variables to consider.
On windows, I have done one client in c++ and one server in python. In order to make the program work, I need first to run the server (in one terminal), and then I can run the client. I am trying to deploy the project and create an installer out of the process. The thing is that I don't know how to run the server alway...
In PHP, there are several ways to check whether a value is true, or similar: true === $v, only works for bool true == $v || !!$v, works with int and string, but a non empty array can also be considered true 1 == $v, works with bool, int, string and always false with arrays Personally, I feel partial to 3. Especially ...
Are stacks and queues allowed to be iterated over, conceptually? It “feels wrong” for some reason but I can't come up with a reason why it would be bad to see through the whole thing that's stacked/queued. Obviously no taking the element out of there, or inserting a new one somewhere in-between. Are my senses off or is...
So the gist is to have a static global variable that can be modified by different executables. For example I have 2 different source files including the same dll.h: dll.h #include <iostream> int globalCounter = 0; __declspec(dllexport) void incrementCounter() { globalCounter++; std::cout << globalCounter << '...
I've been reading about the IEEE 754 standard, but can't understand how or why they chose those exact number of bits for the exponent and mantissa. For example, why 8 bits for the exponent and not 7 or 9 for the single precision? Similarly, why 11 for the double precision? Is there a formula you can use to come to this...
I am working on a project which does not have solid requirements, All is we have meetings with all the teams across and confluence pages. No one owns any requirements and it just float around scattered info and it is confusing and the meetings go no where and management does not care about this chaos. How a software pr...
In my research, I have found two conflicting definitions of 'availability' as it relates to software engineering and architecture. According to [1]: "The availability of a system can be calculated as the probability that it will provide the specified services within required bounds over a specified time interval. When ...
I am working on a project on my own and I am using git just to keep track and to get used to a team environment. When should I commit on the main branch (if I should at all), do I need to create a branch for each feature, bug, etc., and then merge them to main or could smaller things (adding one field to get stored in ...
I am working on a compilers assignment in OCaml, and the following is an example of the pre-written code in said assignment: (* Build a CFG and collection of global variable definitions from a stream *) let cfg_of_stream (code:stream) : Ll.cfg * (Ll.gid * Ll.gdecl) list = let gs, einsns, insns, term_opt, blks = Li...
I have the following domain specs: A historic read only list of items that were published and a currently published item (if any) and an optional draft item (if any). I thought of the following design: Publicly accessible: GET /items # Returns list of items excluding optional draft GET /item/published # returns curr...
Context : I am currently task with building a software to support operators in a manufacturing plant. Due to the nature of the plant, the computers all have fairly weak processing power (given that they can't have any fans and the environment is already hot to begin with). The current "client" is in WinForms and there'...
I wrote some script in Python that creates a giant 2D matrix (1000x1000 or bigger) and fills it with random numbers. And after that, it goes through every element of the matrix and changes the number to another one depending on the current element's neighbours (something like you do in Game Of Life). And I noticed that...
I was reading some examples how to handle concurrency in DDD. One example is in this repository: https://github.com/kgrzybek/efcore-concurrency-handling/tree/master/src/OptimisticConcurrency/DDD.EF.OptimisticConcurrency And the code in which is increased the version is this: public async Task<IActionResult> AddOrderLin...
Here's what I want to achieve: while complex_compound_condition_statement: foobar() # ... do some stuff I would like the log output of the above to be: <timestamp> INFO: started doing stuff on condition Abc <timestamp> INFO: condition Abc no longer active To achieve the above using straight control flow, the curr...
Some of the checks I make to validate http requests involve making a call to an external service to parse part of the request body. These calls can fail because of network connectivity issues. My feeling is that I should return a 5xx error to indicate that the client may want to try again later. However, what do I do...
Something that annoys me when reading about decoupling microservices is that the problem is often stated, with either poorly explained, bad, or no solutions provided, which seems to especially be the case with synchronous communication. Take this basic example of a customer and orders microservice: The customer servic...
I've inherited a system with an Oracle relational database with a couple of tables modeled like I've sketched below, where there's an entire child table that only stores a single status code in a one-to-one relationship with its parent. Here's a generalized sketch of the schema I'm talking about: The ITEM table is qui...
I have the following classes in my system (python): class Metric(ABC): def compute(self): -> float class Visualization(ABC) def visualize(self) class FirstMetric(Metric) def __init__(self, data1): def compute(self): -> float class FirstVisualization(Visualization) def __init__(self, plot_param1, data1...
We have a legacy API service and database at my workplace. My team works on a mobile app that uses this API for some particular data. You can think of this as DDD - our service shares some entities with the legacy API service. Besides using the legacy API, we also use a dedicated API and database for the mobile app's s...