I'd like to buy a book with all the information available in the link below. Is there any book available in the market?
https://docs.microsoft.com/en-us/azure/architecture/patterns
I'd like to buy a book with all the information available in the link below. Is there any book available in the market?
https://docs.microsoft.com/en-us/azure/architecture/patterns
I want to design a baisc application
I want to write an Calculator ( business function ) which takes a list of entities from an Excel file and run calculation on it sequentially/parallel.
Which design pattern fits for this chase ?
I am learning Composite Design Pattern in C++. I get a problem trying to define a general connect_to function as you can see below. The Layer Class works well due to that it inherits from vector. While the Neuron fails to compile because I implements the begin and end by myself. How can I make it work?
class Neuron;
template<typename Self>
class SomeNeurons {
public:
template<typename T>
void connect_to(T& other) {
//C++11 style
for (Neuron& from : *static_cast<Self*>(this)) {
for (Neuron& to : other) {
from.out.push_back(&to);
to.in.push_back(&from);
}
}
}
};
class Neuron :public SomeNeurons<Neuron>{
public:
vector<Neuron*> in, out;
unsigned int id;
Neuron() {
static int id = 1;
this->id = id++;
}
//My implementation
Neuron* beign() {
return this;
}
Neuron* end() {
return this + 1;
}
};
class NeuronLayer :public vector<Neuron>, public SomeNeurons<NeuronLayer> {
public:
NeuronLayer(int count) {
while (count-- > 0) {
emplace_back(Neuron{});
}
}
};
This is a design question. I am trying to implement a Content Moderation Service in python 3.8 which uses AWS Rekognition to detect moderation labels. This service will be implemented using Serverless framework and will execute as AWS Lambda Function. The trigger to this lambda function would be an s3 bucket.
So I have already created a lambda function which gets triggered at every image upload on s3 bucket. And I am able to trigger the AWS Rekognition service with that image as input and fetch the output.
My question is regarding the design of this service. Imagine a web app like LinkedIn, where there are users and organisations who upload images as posts, profile pictures, business pictures, etc. All of these components already have the APIs which upload these images and store the reference in the DB.
This service that I am implementing should receive any kind of image first and should detect moderation labels on it, if everything looks fine than store the reference in db otherwise delete.
What is the best way to implement this?
Limitations:
1). We don't want to rework on the existing legacy code and put a check in every API.
2). This service should not call all the other APIs to store or re-trigger etc.
Let's consider the following example:
(Function<FunctionType> is just a class that applies some function specified by the enum FunctionType)
template<FunctionType funcType>
class System {
public:
void doEverything() {
//Iterate through every module in sequence and call doSomething()
}
void undoEverything() {
//Iterate through every module in sequence and call undoSomething()
}
template<class Derived>
void add(GenericModule<Derived>& module) {
//Add module to list
}
};
template<class Derived>
class GenericModule {
private:
Derived* crtp = static_cast<Derived*>(this);
public:
void doSomething() {
crtp->doSomething();
}
void undoSomething() {
crtp->undoSomething();
}
};
template<FunctionType funcType, int param>
class ModuleA : public GenericModule<ModuleA<funcType, param>> {
private:
Function<funcType> func;
public:
void doSomething() {
std::cout << param+1 << "\n";
}
void undoSomething() {
std::cout << func.doFunction(param) << "\n";
}
};
template<FunctionType funcType, int param1, int param2>
class ModuleB : public GenericModule<ModuleB<funcType, param1, param2>> {
private:
Function<funcType> func;
public:
void doSomething() {
std::cout << param1 + param2 << "\n";
}
void undoSomething() {
std::cout << func.doFunction(param1+param2) << "\n";
}
};
int main() {
System<FUNC1> system;
ModuleA<FUNC1, 1> m1;
ModuleB<FUNC1, 1, 2> m2;
system.add(m1);
system.add(m2);
system.doEverything();
system.undoEverything();
}
Goal: The goal with this is to create multiple modules which together make up a "system" so that with only one call to doEverything() or undoEverything() all their respective functions can be executed in sequence. Important is that all modules of a system share the same FunctionType argument specified in the system template. I intentionally used CRTP as this has to be highly efficient and thus any use of virtual functions is discouraged.
My approach was to use CRTP to create a common interface GenericModule from which all modules can be called. I thought the observer pattern might be suitable to register any module in system.
Problems:
How can I implement the add/register functionality in system? I'm thinking about a heterogeneous container that stores any type of GenericModule or something similar. It's important that this technique has as little overhead as possible which is certainly going to be difficult to implement. I'd also consider a complete re-design of this functionality as this might not be optimal.
The FunctionType argument is only relevant to the System class and not to a particular module. The module still needs this argument for it's functionality and due to efficiency reasons it has to be defined as a template argument so it can be used in a constexpr context. But because this argument is already set in the System class and all it's modules share the same value it's highly redundant for it to be redefined on every instantation of a module. I want to instantiate each module in the context of it's system so that the FunctionType argument doesn't have to be redefined every single time. In combination with that I't might even be possible that System automatically adds/registers the module when it's instantiated in it's context.
I have no clue how I could implement all these afromentioned things and that's why I'm asking you.
Update: I just had an idea on how I could solve the first problem. Instead of storing each module in the System class I could just put a reference to the next module as a member variable in the previous module. But I have not yet figured out how I could set it's type at compile time.
I am trying to solve an issue of concurrency in my system without trying to use locks. So, far I am unable to think of any solution to this. Any suggestions / ideas will be of great help.
Scenario:
There exists two types of entities in my system (stored separately in databases):
There is no sequence to action on templates and documents. Action on both can happen parallely at any point of time.
Following actions happen on Templates
Following actions can happen to documents at any time:
Each of the above operation on documents leads to re-evaluation of the document's membership to the template and the template's current version document is updated to reflect the correct set of document identifiers which are members of the template. For Ex: when a new document is added, it is checked to see if it's attributes matches to ones in the current version of the template and if so, it is added to list of document identifiers in the template.
The concurrency issue arises mainly on the template document and in it's list of member document identifier storage. Since, the updation of member document list for a template can happen parallely between template creation / updation and creation / updation of different documents, this can lead to incorrect data if not handled correctly.
Right now, this is being solved by using a lock such that creation / updation of a template and creation / updation of documents are mutually exclusive.
Are there any mechanisms using which the concurrency can be handled without locks?
Let's say that I have a list of sqlalchemy objects [obj1, obj2..., objn] that I would like to insert into sqlite table if they don't exist, or update if they exist in table.
This list represents successive objects from certain time range. I could have a list with mix of object, some of them that exist and some that don't exist in table.
I could do something like this:
for obj in list:
saved_obj = select obj
if saved_obj:
update saved_obj with changes from obj
else:
insert obj
commit
But, such solution is kind of very ineffective.
I would rather select from time range, than compare time range of objects from table with time range objects from list (they don't have to match one to one), update objects that are changed, insert what's new and commit.
If someone has experience with such mass inserts/updates, please share your experiences, how to do that efficiently with sqlite and sqlalchemy ^= 1.4.